Strange problem with timezone, calendar and SimpleDateFormat(时区、日历和 SimpleDateFormat 的奇怪问题)
问题描述
让我们考虑以下代码:
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss dd/MM/yyyy", Locale.US);
long start = sdf.parse("10:30:00 30/09/2009").getTime();
long end = sdf.parse("10:30:00 30/10/2009").getTime();
Calendar c = Calendar.getInstance(Locale.US);
c.setTimeInMillis(start);
System.out.println("Start = " + c.getTime());
c.setTimeInMillis(end);
System.out.println(" End = " + c.getTime());
运行此代码段时,我有以下输出:
When running this code snippet, I have the following output:
Start = Wed Sep 30 10:30:00 CEST 2009
End = Fri Oct 30 10:30:00 CET 2009
为什么我得到不同的时区?
Why do I get different timezone ?
请注意,如果我将第一个日期设置为 8 月,第二个日期设置为 9 月,则两种情况下的输出将显示相同的时区:
Note that if I set the first date in august and the second one in september, the output will display the same timezone in both cases:
long start = sdf.parse("10:30:00 30/08/2009").getTime();
long end = sdf.parse("10:30:00 30/09/2009").getTime();
将显示:
Start = Sun Aug 30 10:30:00 CEST 2009
End = Wed Sep 30 10:30:00 CEST 2009
我使用的是 Java 1.6.0_14
I'm using Java 1.6.0_14
推荐答案
CEST 是中欧夏令时.与夏令时生效的 CET 相同.
CEST is Central European Summer Time. It is the same as CET with daylight savings into effect.
这篇关于时区、日历和 SimpleDateFormat 的奇怪问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:时区、日历和 SimpleDateFormat 的奇怪问题
基础教程推荐
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
