问题
I am trying to change the format of a date but cannot get it to work from Nov 18, 2014 to 2014-11-18
String s="Nov 18, 2014"
s= new SimpleDateFormat("yyyy-MM-dd").format(new SimpleDateFormat("LLL dd, yyyy").parse(s));
something is wrong with this part
new SimpleDateFormat("LLL dd, yyyy").parse(s)
回答1:
Change LLL
to MMM
and it should work. LLL
is not defined (corrent value). You should look at
- Class SimpleDateFormat at official docs
- Common Pattern Strings for java.text.SimpleDateFormat
As @Reimeus pointed out LLL
keyword should work but for Android platform. Here are official docs.
回答2:
Your default Locale
may not match the month field in the input String
. Try
new SimpleDateFormat("LLL dd, yyyy", Locale.ENGLISH)
回答3:
it is not LLL, it is MMM
Change it to
new SimpleDateFormat("yyyy-MM-dd").format(new SimpleDateFormat("MMM dd, yyyy", Locale.US).parse(s));
回答4:
It seems like LLL
doesn't exist ; if you want the format for months, it's MMM
instead.
回答5:
new SimpleDateFormat("LLL dd, yyyy").parse(s)
should be changed to new SimpleDateFormat("MMM dd, yyyy").parse(s)
来源:https://stackoverflow.com/questions/27159646/change-date-format-nov-18-2014-to-2014-11-18