Java日期,使用特定的日光模式进行渲染 [英] Java Date, render with specific daylight mode

查看:119
本文介绍了Java日期,使用特定的日光模式进行渲染的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在夏季夏令时期间有一个Java Date 。例如:

I have a Java Date that is from this summer during daylight savings time. For example:


2009年6月1日上午06:00 PDT

Jun 01, 2009 06:00 AM PDT

我的问题是,如何将此日期显示为本地时区和当前夏令时(在我的情况下是太平洋标准时间)?

My question is, how do I display this date as my local time zone and current daylight savings mode (in my case Pacific Standard Time)?


2009年6月1日05:00 AM PST

Jun 01, 2009 05:00 AM PST

Java的 Date.toString() SimpleDateFormat 原始夏令时模式显示日期。示例:

Java's Date.toString() and SimpleDateFormat displays the date in the original daylight savings mode. Example:

System.out.println(new Date(1243861200000L));

输出:


Mon Jun 01 06:00:00 PDT 2009

Mon Jun 01 06:00:00 PDT 2009



DateFormat dateFormat = new SimpleDateFormat("MMM dd, yyyy hh:mm aa zzz");
dateFormat.setTimeZone(TimeZone.getTimeZone("PST"));
System.out.println(dateFormat.format(new Date(1243861200000L)));

输出:


2009年6月1日上午06:00 PDT

Jun 01, 2009 06:00 AM PDT

我真正想看到的是PST(上午5:00)相当于上午6:00 PDT)。有没有办法强制使用另一个夏令时模式?

What I really want to see is 5:00 AM PST (which is equivalent to 6:00 AM PDT). Is there a way to force it to use another daylight savings mode?

跟进:顺便提一句,这是Windows XP的行为。在6月1日上午5点,冬天期间将在6月1日上午6点创建一个文件(由Explorer,Command Prompt等)。

Follow up: By the way, this is the Windows XP behavior. A file created on June 1, 6 AM will be seen (by Explorer, Command Prompt, etc) as June 1, 5 AM during the winter.

推荐答案

PST / PDT全年变化。 Java尝试确定在给定日期中哪个有效。随着法律和地区的变化,这件事情明显的改变了。你可以使用绝对时区吗?指定GMT的偏移量将在同一年。

PST/PDT change throughout the year. Java attempts to determine which one is in affect on a given date. This things obviously change as the laws and regions change. Can you use an absolute time zone? Specifying the offset in GMT will be the same year around.

    DateFormat dateFormat = new SimpleDateFormat("MMM dd, yyyy hh:mm aa zzz");
    dateFormat.setTimeZone(TimeZone.getTimeZone("GMT-07:00"));
    System.out.println(dateFormat.format(new Date(1243861200000L)));

Jun 01, 2009 06:00 AM GMT-07:00

这篇关于Java日期,使用特定的日光模式进行渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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