日历在错误的时区中返回日期 [英] Calendar returns date in wrong time zone
本文介绍了日历在错误的时区中返回日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我在格林尼治标准时间(GMT)时区在计算机上执行以下操作
If I execute the following on a computer in the GMT timezone
TimeZone timeZone = TimeZone.getTimeZone('IST'); // India Standard Time
Calendar calendar = Calendar.getInstance(timeZone);
System.out.println(calendar.getTime());
它打印
2014年10月31日星期五15:18:22 GMT
Fri Oct 31 15:18:22 GMT 2014
为什么在计算机的默认时区打印日期,而不是在构造Calendar
的TimeZone
上打印日期?
Why is the date printed in the computer's default time zone, rather than the TimeZone
the Calendar
was constructed with?
推荐答案
,因为Date
对象的状态没有时区,因此您需要SimpleDateFormat来格式化和打印所需时区中的日期
because Date
object doesn't have timezone as part of its state, You need SimpleDateFormat to format and print the date in your required timezone
这篇关于日历在错误的时区中返回日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文