Change date format Nov 18, 2014 to 2014-11-18

*爱你&永不变心* 提交于 2019-12-11 09:38:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!