Java:请教两种获取UTC时间的方式有什么不同?
PHP中文网
PHP中文网 2017-04-18 09:19:46
0
1
235

方式一:

Calendar calendar = Calendar.getInstance();
int offset = calendar.get(Calendar.ZONE_OFFSET); 
calendar.add(Calendar.MILLISECOND, -offset);
Date date = calendar.getTime(); 

方式二:

Calendar calendar = Calendar.getInstance();
calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
Date date = calendar.getTime();
PHP中文网
PHP中文网

认证高级PHP讲师

reply all(1)
小葫芦

The second one gets the time in GMT time zone, and the first one gets the time before the current time zone. Use Date.format() to print and see the effect.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template