如何将日期转换为这种格式2015-02-27T15:14:13-06:00 [英] how to convert date to this format 2015-02-27T15:14:13-06:00
问题描述
我需要将日期转换为这种格式2015-02-27T15:14:13-06:00
I need to convert date to this format 2015-02-27T15:14:13-06:00
我尝试使用SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
,但是此生成为2015-04-09T10:39:19-04
I have tried with SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
, but this one generating as 2015-04-09T10:39:19-04
Tks
推荐答案
您可以使用具有ISO日期格式和解析器的新Yoda时间,也可以使用"yyyy-MM-dd的SimpleDateFormat
'T'HH:mm:ssZ" 会为您提供"ccyy-mm-ddThh:mm:ss + zzzz",并手动插入多余的冒号.
You can either use the new Yoda time which has ISO date formatters and parsers or you can use a SimpleDateFormat
of "yyyy-MM-dd'T'HH:mm:ssZ" which gives you "ccyy-mm-ddThh:mm:ss+zzzz" and insert the extra colon manually.
类似的东西:
new StringBuilder(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(date)).insert(22,':').toString();
这篇关于如何将日期转换为这种格式2015-02-27T15:14:13-06:00的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!