MangoCool

GMT、UTC、DST、CST时区代表的意义

2022-05-19 09:34:08   作者:简书/CSDN   来源:简书/CSDN

GMT:Greenwich Mean Time

格林威治标准时间 ; 英国伦敦格林威治定为0°经线开始的地方,地球每15°经度 被分为一个时区,共分为24个时区,相邻时区相差一小时;例: 中国北京位于东八区,GMT时间比北京时间慢8小时。


UTC: Coordinated Universal Time

世界协调时间;经严谨计算得到的时间,精确到秒,误差在0.9s以内, 是比GMT更为精确的世界时间


CST:

四个不同时区的缩写:

  1. Central Standard Time (USA) UT-6:00 美国标准时间
  2. Central Standard Time (Australia) UT+9:30 澳大利亚标准时间
  3. China Standard Time UT+8:00 中国标准时间
  4. Cuba Standard Time UT-4:00 古巴标准时间


DST: Daylight Saving Time

夏季节约时间,即夏令时;是为了利用夏天充足的光照而将时间调早一个小时,北美、欧洲的许多国家实行夏令时;


时间戳:timestamp

表示从1970年1月1日 00:00:00到现在所经历的秒/毫秒数,与时区无关


Java示例代码:

public static void main(String[] args) {
	DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	Date date = new Date();
	String datetime;
	System.out.println("------------------GMT------------------");

	// 已经@Deprecated
	System.out.println(date.toGMTString());

	dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
	datetime = dateFormat.format(date);
	System.out.println(datetime);

	System.out.println("------------------UTC------------------");

	dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
	datetime = dateFormat.format(date);
	System.out.println(datetime);

	System.out.println("------------------CST------------------");
	System.out.println(date);
	// 已经@Deprecated
	System.out.println(date.toLocaleString());

	System.out.println("---------------------------------------");
	DateFormat bjDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	Date bjDate = new Date();// 北京时间(默认时区的时间)
	System.out.println("这是北京时间:" + bjDateFormat.format(bjDate));

	DateFormat newYorkDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	// 纽约时区
	TimeZone newYorkTimeZone = TimeZone.getTimeZone("America/New_York");
	// 根据此时区 将北京时间转换为纽约的Date
	newYorkDateFormat.setTimeZone(newYorkTimeZone);
	System.out.println("这是纽约时间:" + newYorkDateFormat.format(bjDate));

	DateFormat londonDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	// 伦敦时区
	londonDateFormat.setTimeZone(TimeZone.getTimeZone("Europe/London"));
	System.out.println("这是伦敦时间:" + londonDateFormat.format(bjDate));
}

结果输出:

------------------GMT------------------
19 May 2022 03:04:06 GMT
2022-05-19 03:04:06
------------------UTC------------------
2022-05-19 03:04:06
------------------CST------------------
Thu May 19 11:04:06 CST 2022
2022-5-19 11:04:06
---------------------------------------
这是北京时间:2022-05-19 11:04:06
这是纽约时间:2022-05-18 23:04:06
这是伦敦时间:2022-05-19 04:04:06


参考来源:

https://www.jianshu.com/p/735e8444cdda

https://blog.csdn.net/kevinxxw/article/details/124292686

标签: java UTC GMT CST

分享:

上一篇JNI Demo in linux(在linux环境下的JNI示例程序)

下一篇如何使你的tomcat启动更快

关于我

崇尚极简,热爱技术,喜欢唱歌,热衷旅行,爱好电子产品的一介码农。

座右铭

当你的才华还撑不起你的野心的时候,你就应该静下心来学习,永不止步!

人生之旅历途甚长,所争决不在一年半月,万不可因此着急失望,招精神之萎葸。

Copyright 2015- 芒果酷(mangocool.com) All rights reserved. 湘ICP备14019394号

免责声明:本网站部分文章转载其他媒体,意在为公众提供免费服务。如有信息侵犯了您的权益,可与本网站联系,本网站将尽快予以撤除。