Win a copy of Functional Design and Architecture this week in the Functional programming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Changing a String Representing a Date Format

 
Ranch Hand
Posts: 2119
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am getting as UnParseableDate Exception on the following. My parameter = "02/15/2017"

 
Marshal
Posts: 73953
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please print out the String you are using.
You are showing a String in MM/dd/yyyy format and telling the simple date format object to use ddMMMyyyy. That won't work, will it?
If possible, stop using Calendar and use the newer date time classes instead.
 
Steve Dyke
Ranch Hand
Posts: 2119
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Please print out the String you are using.
You are showing a String in MM/dd/yyyy format and telling the simple date format object to use ddMMMyyyy. That won't work, will it?
If possible, stop using Calendar and use the newer date time classes instead.



Does not appear to work as you said.

I need to take a date posted as "02/15/2017"(jquery date picker) and reformat it to 02FEB2017.

I do use JODA in some of my other code. I just have not had time to replace all the Calendar code with it yet.
 
Campbell Ritchie
Marshal
Posts: 73953
332
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But you are giving the input format to the output format. You need one format for input, which is what you are doing. You want input in MM/dd/yyyy format and then output from the Date object in ddMMMyyyy format. As an alternative you can use String#format and the %Tx tags to format the Date into a String.
 
Sheriff
Posts: 8064
569
Mac OS X VI Editor BSD Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to parse by specifying your format, then format. Something similar could work:
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic