How can I parse UTC date/time (String) into something more readable?

前端 未结 10 876
深忆病人
深忆病人 2020-12-13 04:07

I have a String of a date and time like this: 2011-04-15T20:08:18Z. I don\'t know much about date/time formats, but I think, and correct me if I\'m wrong, that\

10条回答
  •  情歌与酒
    2020-12-13 05:06

    Use JodaTime

    I kept getting parsing errors using the other solutions with the Z at the end of the format.

    Instead, I opted to leverage JodaTime's excellent parsing functionality and was able to do the following very easily:

    String timestamp = "2011-04-15T20:08:18Z";
    
    DateTime dateTime = ISODateTimeFormat.dateTimeParser().parseDateTime(timestamp);
    

    This correctly recognizes the UTC timezone and allows you to then use JodaTime's extensive manipulation methods to get what you want out of it.

    Hope this helps others.

提交回复
热议问题