incorrect conversion of String into date format

前端 未结 3 1379
一整个雨季
一整个雨季 2021-01-26 11:56

I am trying to format a string into specific date format but there is some problem in conversion. In converted string month is always coming \"January\". Following is the code s

相关标签:
3条回答
  • 2021-01-26 12:31

    Please use "dd/MM/yyyy-hh:mm:ss"

    0 讨论(0)
  • 2021-01-26 12:38

    As others have said, you should use MM for months - and I strongly suspect you always want to use HH for hours, instead of hh. HH is the 24 hour clock; hh is the 12 hour clock, usually used in conjunction with an AM/PM designator.

    Finally, you should consider what time zone and locale you want your SimpleDateFormat to use. Even in this case where there aren't any month or day names, I'd still specify the locale explicitly, to make it clear that you're not trying to use any localized data.

    SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy-HH:mm:ss", Locale.US);
    // TODO: Set the time zone appropriately
    
    0 讨论(0)
  • 2021-01-26 12:41

    Use MM instead of mm for the date portion of your format string. mm is for minutes, not months.

    Reference: http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html

    0 讨论(0)
提交回复
热议问题