gpt4 book ai didi

java - 在java中将时间戳转换为ISO860,

转载 作者:行者123 更新时间:2023-11-28 16:13:01 25 4
gpt4 key购买 nike

Possible Duplicate:
Converting ISO8601-compliant String to java.util.Date

我在 JS 中将时间戳更改为 ISO 8601 时遇到问题,因为它在 IE 和 Firefox 中的“topicDate”处出错,但它在 Chrome 中有效。所以我想在服务器端将时间戳更改为 ISO 8601 并通过 json 发送。谁能帮助我如何使用标准类将下面的时间戳转换为 Java 中的 ISO 8601 格式?也欢迎任何有关此方法的其他建议。

通过 json 发送时间

 "topic_lstUpdate" : "2012-09-07 19:39:56.439",

JS脚本

var topicDate = new Date(args.topic_lstUpdate);
var topicDateISO = topicDate.toISOString();
var topicDateTimeago=jQuery.timeago(topicDate);

最佳答案

要在服务器端使用 Java 进行格式化:

DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S'Z'");
df.setTimeZone(TimeZone.getTimeZone("UTC"));
String my8601formattedDate = df.format(new Date());

建议您包含 T 分隔符 - 但如果您确定两端的要求都允许排除它,则可以省略它。请参阅http://en.wikipedia.org/wiki/ISO_8601#Combined_date_and_time_representations了解详情。

关于java - 在java中将时间戳转换为ISO860,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12326976/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com