【发布时间】:2018-07-10 12:25:08
【问题描述】:
尝试1:
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS+/-HHmm");
format.setTimeZone(TimeZone.getTimeZone("GMT"));
Date date = format.parse(createdDate2);
尝试2:
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd\'T\'HH:mm:ss.SSS\'Z\'");
format.setTimeZone(TimeZone.getTimeZone("GMT"));
Date date = format.parse(createdDate2);
尝试 3:
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
format.setTimeZone(TimeZone.getTimeZone("GMT"));
Date date = format.parse(createdDate2);
这种格式似乎不起作用:
有什么帮助吗?
【问题讨论】:
-
您使用
SimpleDateFormat、TimeZone和Date类的任何特殊原因?这些都已经过时了,SimpleDateFormat特别是出了名的麻烦。今天我们在java.time, the modern Java date and time API 中做得更好。 -
猜猜看,为什么 Oracle 没有完全弃用 Date 对象?因为仍然有很多代码使用日期对象...
标签: java simpledateformat