• Post Reply Bookmark Topic Watch Topic
  • New Topic

I can't read a String date to date  RSS feed

 
joe encalada
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please some help I dont know how to solve this problem.
Here is the code I've found in this website: https://www.mkyong.com/java/how-to-convert-string-to-date-java/



According to that page this is the output:

Fri Jun 07 12:10:56 MYT 2013
Friday, Jun 07, 2013 12:10:56 PM

But to my only get  :  java.text.ParseException: Unparseable date: "Friday, Jun 7, 2013 12:10:56 PM"

Can you tell me where is my error.
 
Ron McLeod
Bartender
Posts: 1602
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is most likely because of your locale.  Do you see a proper result if you set dateInString to "Viernes, Jun 7, 2013 12:10:56 PM"?
 
Ron McLeod
Bartender
Posts: 1602
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to run the code using the date strings in the examples, try setting the locale to US (or other English language locale):

SimpleDateFormat formatter = new SimpleDateFormat("EEEE, MMM dd, yyyy HH:mm:ss a", Locale.US);
 
joe encalada
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Ron it did the trick.

 
Campbell Ritchie
Marshal
Posts: 56540
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe everybody shoul‍d stop using Date. Use the newer classes instead. I think you want a LocalDateTime object. Try this method.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!