本文介绍了时区、日历和 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 的奇怪问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!
The End


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)