• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can't parse a String date  RSS feed

 
van tan
Greenhorn
Posts: 1
  • 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.
 
Tim Moores
Saloon Keeper
Posts: 4023
94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What output do you get if you replace line 14 with "Date date = new Date() ;"?
 
Campbell Ritchie
Marshal
Posts: 56520
172
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I would suggest you stop using Date and use the newer date and time classes instead.
 
Mike London
Ranch Hand
Posts: 1505
11
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Welcome to the Ranch

I would suggest you stop using Date and use the newer date and time classes instead.


+1

The new Java date classes are incredible.

To create today's date, you just need to do something like this:

final LocalDate now = LocalDate.now();

--

Although there are tons of great tutorials on the new Java 8 API, here's one of them: https://www.tutorialspoint.com/java8/java8_datetime_api.htm

I highly recommend you use the new date APIs ... SO much better than the older tired date API.

- mike
 
Knute Snortum
Sheriff
Posts: 4270
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is your Locale?  You can see this by executing:

System.out.println(Locale.getDefault());

If it's not en_US that may be the problem.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!