试试这个(Java 8):
String input = "2016-10-14T14:19:40-04:00";
String output = ZonedDateTime.parse(input).toInstant().toString();
System.out.println(output); // prints 2016-10-14T18:19:40Z
Run Code Online (Sandbox Code Playgroud)
这是有效的,因为ZonedDateTimeby 使用的主要格式parse()是ISO_ZONED_DATE_TIME,因此它将以您描述的格式解析输入。
您请求的输出格式恰好是 的默认格式Instant,由其toString()方法返回,即ISO_INSTANT格式。
两者之间的转化(ZonedDateTime以Instant使用toInstant()方法)将执行时区调整必要的。
| 归档时间: |
|
| 查看次数: |
7269 次 |
| 最近记录: |