-1
我想解析以下日期格式'2017-02-16T17:29:12.12T + 0200'到ZonedDateTime
。Java日期自定义格式为ZonedDateTime
我的目标是让ZonedDateTime
持有2017-02-16T17:29:12.12未经修改(未转移到系统时区)并与+2小时(从GMT)表示的时区相关联。
@Test
public void testParseCustomDate() throws Exception {
String format = "yyyy-MM-dd'T'HH:mm:ss.S'T'Z";
String value = "2017-02-16T17:29:12.12T+0300";
Date date = new SimpleDateFormat(format).parse(value);
System.out.println(date);
ZonedDateTime dateTime = ZonedDateTime.parse(value, DateTimeFormatter.ofPattern(format));
System.out.println(dateTime);
}
在日期上面的例子中被成功地由SimpleDateFormat
解析,但不与ZonedDateTime.parse
谢谢它有助于 – endryha