gpt4 book ai didi

java - 将 UTC 转换为当前语言环境时间

转载 作者:IT老高 更新时间:2023-10-28 20:50:33 26 4
gpt4 key购买 nike

我正在从网络服务下载一些 JSON 数据。在这个 JSON 中,我有一些日期/时间值。一切都以 UTC 为准。如何解析此日期字符串,以便结果 Date 对象位于当前语言环境中?

例如:服务器返回“2011-05-18 16:35:01”,我的设备现在应该显示“2011-05-18 18:35:01”(GMT +2)

我当前的代码:

SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date myDate = simpleDateFormat.parse(rawQuestion.getString("AskDateTime"));

最佳答案

它有一个设置时区方法:

SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
Date myDate = simpleDateFormat.parse(rawQuestion.getString("AskDateTime"));

全部完成!

关于java - 将 UTC 转换为当前语言环境时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6049207/

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