"EEEE, MMMM d, yyyy" in "HH: mm"

I am trying to convert from string to date. Example: Wednesday, September 4, 2013 at 17:07.

I will first convert it to: Wednesday, September 4, 2013, 17:07

And use the following code:

SimpleDateFormat format = new SimpleDateFormat("EEEE, MMMM d, yyyy 'at' hh:mm a"); 

But I always get Unparseable date Exception.

Any help is appreciated!

+4
source share
3 answers

The following works for me:

 String str = "Wednesday, September 4, 2013 at 5:07 PM"; SimpleDateFormat format = new SimpleDateFormat("EEEE, MMMM d, yyyy 'at' hh:mm a", Locale.US); 

But if I remove Locale , then I will get a ParseException . Your Locale computer may not correspond to the language version of the language.

+3
source

This works fine:

 SimpleDateFormat in = new SimpleDateFormat("EEEE, MMMM d, yyyy 'at' hh:mma"); Date date = in.parse("Wednesday, September 4, 2013 at 5:07pm"); SimpleDateFormat out = new SimpleDateFormat("EEEE, MMMM d, yyyy 'at' hh:mm a"); String result = out.format(date); System.out.println(result); 
0
source

Why not use dd instead of d

So, instead of:

 SimpleDateFormat format = new SimpleDateFormat("EEEE, MMMM d, yyyy 'at' hh:mm a"); 

Using:

 SimpleDateFormat format = new SimpleDateFormat("EEEE, MMMM dd, yyyy 'at' hh:mm a"); 
0
source

Source: https://habr.com/ru/post/1501548/


All Articles