java.util.Date 中的默认时区是什么
如果我创建一个新的 Date() 对象.它将打印的默认时区是什么.
If i create a new Date() object. What will be the default timezone it will print.
我的机器在 GMT 运行.我正在创建一个新的 Date() 对象.如果我打印为什么它显示 Thu Jul 05 08:21:05 PKT 2012.它如何将时区作为 PKT ?
I have my machine running in GMT. And i am creating a new Date() object. If i print why does it shows Thu Jul 05 08:21:05 PKT 2012. How does it takes the timezone as PKT ?
推荐答案
日期本身没有任何时区.它的 toString()
方法使用当前默认时区返回一个表示该日期的字符串:
The date itself doesn't have any time zone. Its toString()
method uses the current default time zone to return a String representing this date:
Date date = new Date();
System.out.println(TimeZone.getDefault());
System.out.println(date);
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
System.out.println(TimeZone.getDefault());
System.out.println(date);
在我的机器上执行上面的代码会得到以下输出:
Executing the above code on my machine leads to the following output:
sun.util.calendar.ZoneInfo[id="Europe/Paris",offset=3600000,dstSavings=3600000,useDaylight=true,transitions=184,lastRule=java.util.SimpleTimeZone[id=Europe/Paris,offset=3600000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMonth=2,startDay=-1,startDayOfWeek=1,startTime=3600000,startTimeMode=2,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=3600000,endTimeMode=2]]
Fri Jul 06 09:24:45 CEST 2012
sun.util.calendar.ZoneInfo[id="UTC",offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null]
Fri Jul 06 07:24:45 UTC 2012
相关文章