Java SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'") 将时区作为 IST [英] Java SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'") gives timezone as IST

查看:42
本文介绍了Java SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'") 将时区作为 IST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 SimpleDateFormat 构造函数

I have SimpleDateFormat constructor as

SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")

我正在解析字符串 "2013-09-29T18:46:19Z".

我读到这里 Z 代表 GMT/UTC 时区.但是当我在控制台上打印这个日期时,它会为返回的日期打印 IST timezne.

I have read that here Z represents the GMT/UTC timezone. but when I print this date on console , It prints IST timezne for the returned date.

现在我的问题是我的输出是对还是错?

Now my question is whether my output is right or wrong?

推荐答案

你没有设置时区只是在日期/时间的末尾添加了一个 Z,所以它看起来像一个GMT 日期/时间,但这不会改变值.

You haven't set the timezone only added a Z to the end of the date/time, so it will look like a GMT date/time but this doesn't change the value.

将时区设置为 GMT,它就会正确.

Set the timezone to GMT and it will be correct.

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));

这篇关于Java SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'") 将时区作为 IST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆