Simple date formatting giving wrong time

后端 未结 4 1734
暗喜
暗喜 2021-01-20 05:57

I am trying to parse a String to a Date and it giving me right date where as time is wrong.

SimpleDateFormat formatter = new SimpleDateFormat(\"yyyy-MM-dd HH         


        
4条回答
  •  温柔的废话
    2021-01-20 06:27

    Maybe its related to time zone issues, at what time zone is your input?, i'd suggest to make sure your paramater is on UTC timezone and then using formatter like this :

    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm aaa");
    formatter .setTimeZone(TimeZone.getTimeZone("UTC"));
    

提交回复
热议问题