• Post Reply Bookmark Topic Watch Topic
  • New Topic

Changing a String Representing a Date Format  RSS feed

 
Steve Dyke
Ranch Hand
Posts: 1782
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting as UnParseableDate Exception on the following. My parameter = "02/15/2017"

 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • 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: 1782
1
  • Mark post as helpful
  • send pies
  • 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: 56529
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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.
 
Liutauras Vilda
Sheriff
Posts: 4917
334
BSD
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to parse by specifying your format, then format. Something similar could work:
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!