调整系统的时区后,在任务栏的时间显示马上就切换到了响应时区的日期显示,但是为什么在程序一直运行期间更改时区之后,程序打印的时间不会出现跳跃?如果再次执行程序,这是时候时区修改的效果才能看到?难道是程序运行起来后,只与系统交互一次获取时区后,不再与OS交互,只有程序再次执行才会在程序启动的时候读取当前时区?[code]
package com.free.timezone.test;import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;public class TestTimeZone
{
public static void main(String[] args)
{
while(true)
{
Date dd = new Date();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//打印时间
System.out.println(df.format(dd));
TimeZone tz = TimeZone.getDefault();
//打印时区名称
System.out.println(tz.getDisplayName());
try
{
Thread.sleep(5000);
} catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
}[/code]
修改时区为 美国时区前后,程序一直执行后的打印2007-07-19 22:16:49
中国标准时间
2007-07-19 22:16:54
中国标准时间
2007-07-19 22:16:59
中国标准时间
修改时区为 美国时区,程序重新执行后的打印
2007-07-19 09:17:26
中央标准时间
2007-07-19 09:17:31
中央标准时间
package com.free.timezone.test;import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;public class TestTimeZone
{
public static void main(String[] args)
{
while(true)
{
Date dd = new Date();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//打印时间
System.out.println(df.format(dd));
TimeZone tz = TimeZone.getDefault();
//打印时区名称
System.out.println(tz.getDisplayName());
try
{
Thread.sleep(5000);
} catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
}[/code]
修改时区为 美国时区前后,程序一直执行后的打印2007-07-19 22:16:49
中国标准时间
2007-07-19 22:16:54
中国标准时间
2007-07-19 22:16:59
中国标准时间
修改时区为 美国时区,程序重新执行后的打印
2007-07-19 09:17:26
中央标准时间
2007-07-19 09:17:31
中央标准时间
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货