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

前端 未结 10 871
深忆病人
深忆病人 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条回答
  •  -上瘾入骨i
    2020-12-13 04:48

    The Java 7 version of SimpleDateFormat supports ISO-8601 time zones using the uppercase letter X.

    String string = "2011-04-15T20:08:18Z";
    DateFormat iso8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
    Date date = iso8601.parse(string);
    

    If you're stuck with Java 6 or earlier, the answer recommending JodaTime is a safe bet.

提交回复
热议问题