incorrect conversion of String into date format

前端 未结 3 1443
一整个雨季
一整个雨季 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: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
    

提交回复
热议问题