Java验证只有一个时间戳

问题

每个不同的地区都有对应有不同时间戳吗?

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//: 通过程序证明来时间戳只有一个;
public class TimeTest {

public static void main(String[] args) {
Calendar now = new GregorianCalendar();
System.out.println(TimeZone.getDefault());
System.out.println(now.getTime());
System.out.println(now.getTime().getTime());
System.out.println();

TimeZone.setDefault(TimeZone.getTimeZone("GMT+8"));
System.out.println(TimeZone.getDefault());
System.out.println(now.getTime());
System.out.println(now.getTime().getTime());
System.out.println();

TimeZone.setDefault(TimeZone.getTimeZone("GMT+0"));
System.out.println(TimeZone.getDefault());
System.out.println(now.getTime());
System.out.println(now.getTime().getTime());
System.out.println();

TimeZone.setDefault(TimeZone.getTimeZone("GMT+12"));
System.out.println(TimeZone.getDefault());
System.out.println(now.getTime());
System.out.println(now.getTime().getTime());
}
}
/*
sun.util.calendar.ZoneInfo[id="Asia/Shanghai",offset=28800000,dstSavings=0,useDaylight=false,transitions=19,lastRule=null]
Thu Aug 10 09:39:22 CST 2017
1502329162745

sun.util.calendar.ZoneInfo[id="GMT+08:00",offset=28800000,dstSavings=0,useDaylight=false,transitions=0,lastRule=null]
Thu Aug 10 09:39:22 GMT+08:00 2017
1502329162745

sun.util.calendar.ZoneInfo[id="GMT+00:00",offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null]
Thu Aug 10 01:39:22 GMT+00:00 2017
1502329162745

sun.util.calendar.ZoneInfo[id="GMT+12:00",offset=43200000,dstSavings=0,useDaylight=false,transitions=0,lastRule=null]
Thu Aug 10 13:39:22 GMT+12:00 2017
1502329162745
*///~

结论

只有一个时间戳;
时间戳在所有地方都是一样的,只不过是该时间戳对应不同的地区有不同的当地时间表示(而不是有每个地区都有一个不同的时间戳)。