千钻公会程序员Web前端之路

你会见证11位时间戳的出现!

2019-01-04  本文已影响10人  zhaoolee

从格林尼治时间1970年1月1日0时0分0秒算起(北京时间1970年1月1日8时0分0秒), 开始计算时间戳


时间戳大致分两种格式

时间戳可以用多久呢?

一年31536000秒,时间戳最多纪录 9999999999秒, 9999999999/31536000 ≈ 317 年, 10位的时间戳大约可以使用317年, 1970+317=2287年,也就是2286年就要考虑变更到11位时间戳了

如果精确计算一下(考虑闰年)

Python时间戳默认是10位(精确到秒)

import time
# 获取时间戳
timestamp = int(time.time())
print(timestamp)
# 将时间戳转换为结构化时间格式
struct_time = time.localtime(timestamp)
print(struct_time)

Javascript时间戳默认是13位(精确到毫秒)

// 获取毫秒时间戳(13位)
let timestamp = new Date().getTime();
console.log(timestamp);
// 将毫秒时间戳转换为结构化时间格式
let struct_time = new Date(timestamp);
console.log(struct_time);

小结

上一篇 下一篇

猜你喜欢

热点阅读