跳至正文
Wener Notes

timezone

约 2 分钟阅读
text
2024-03-15T06:00:00.000+08:00
abbr.foroffsetcn
CSTChina Standard Time+08
中国标准时间
UTCCoordinated Universal Time+00
世界协调时间
GMTGreenwich Mean Time+00
格林尼治标准时间
ESTEastern Standard Time-05
东部标准时间
PSTPacific Standard Time-08
太平洋标准时间
EDTEastern Daylight Time-04
东部夏令时间
PDTPacific Daylight Time-07
太平洋夏令时间

shell

bash
adjtimex  # 确认时间同步
date +%z  # +0800
date +%:z # +08:00
date +%Z  # CST
TZ=UTC date
TZ=Asia/Shanghai date

JS Date.prototype.toJSON

JavaScript
// 默认 toJSON 为 UTC
const now = new Date(2021, 12, 12, 0, 0, 0);
// now.getTimezoneOffset() // local timezone offset
console.assert(now.toJSON() === now.toISOString());
JSON.stringify({ now });

Date.prototype.toJSON = function () {
  // return moment(this).format();
  // return format(new Date(2016, 0, 1), "yyyy-MM-dd'T'HH:mm:ss.SSSxxx") // date-fns
  return dayjs(this).format();
};
methodformat
now.toJSON()2022-01-11T16:00
.000Z
moment(now).format()2022-01-12T00:00
+08
dayjs(now).format()2022-01-12T00:00
+08
date-fns format(now, "yyyy-MM-dd'T'HH:mm
.SSSxxx")
2022-01-12T00:00
.000+08

JS Date timezone offset

TypeScript
new Date(2023, 2, 18); // 2023-03-17T16:00:00.000Z
new Date(Date.UTC(2023, 2, 18)); // 2023-03-18T00:00:00.000Z

Java

  • JVM -Duser.timezone=Asia/Shanghai

sprintboot

xml
<properties>
  <spring-boot.run.jvmArguments>-Duser.timezone=UTC</spring-boot.run.jvmArguments>
</properties>

MySQL

sql
show global variables like '%time_zone';

select now();
varval
system_time_zoneCST
time_zoneSYSTEM
  • UTC - Coordinated Universal Time - 世界标准时间
  • GMT - Greenwich Mean Time - 格林尼治标准时间
  • CST
    • China Standard Time - 中国标准时间 - UT+8
    • Central Time Zone - 北美中部时间 USA - UT-6
    • Cuba Standard Time UT-4
  • EST - Eastern Time Zone
  • timezonedb.com/time-zones/Asia/Shanghai

关联信息

反向链接、本文链接的其他页面和外部资料。

参考资料

Wikipedia1 条
其他外链1 条
最近更新commit 2de2575编辑