【发布时间】:2017-01-11 16:22:17
【问题描述】:
我正在尝试从 UTC 时间戳获取本地时间并计算偏移量。 我有一个 UTC 时间 =1484063246 这是我的代码。
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
dateFormat.setTimeZone(TimeZone.getTimeZone("CET"));
String formattedDate = dateFormat.format(new Date(1484063246L * 1000L));
formattedDate 以日期格式返回。如何根据这些值计算 UTC 时间和本地时间之间的差异。如何根据服务器运行的位置而不是硬编码“CET”来设置TimeZone。
【问题讨论】: