分享在命令行转换时间戳到可读时间的工具

2017-10-14 10:59:36 +08:00
 scriptB0y

搜了一下好像没有现成的能转换时间戳的工具,我比较常用这个需求,就写了个脚本。非常简单,几乎就接收一个输入然后打印出来。

放到 bin 里面以后可以方便的用啦。

https://gist.github.com/laixintao/142347c7a2e00c432b8004c0ab4ce3bb

https://gist.github.com/laixintao/f86f63bdfc619f8b71c131d17daa5713

3495 次点击
所在节点    分享发现
15 条回复
lululau
2017-10-14 11:02:05 +08:00
Mac: date -r 1514131200
GNU/Linux: date -d @1514131200
siguretto
2017-10-14 11:03:32 +08:00
why not `date -r` ?
scriptB0y
2017-10-14 11:13:35 +08:00
@lululau @siguretto

谢谢我火星了……之前怎么没发现。。。
oott123
2017-10-14 11:15:13 +08:00
其实我都是 irb
Time.at xxx
Dwyanetalk
2017-10-14 11:17:20 +08:00
@lululau date 请问可以指定时区吗?或者 date 是根据什么判断时区的?有什么工具处理时区的问题?
pheyer
2017-10-14 11:17:52 +08:00
Mac 下有一个 alfred workflow 叫 datetime format convert 可以做这个
CloudnuY
2017-10-14 11:19:10 +08:00
scriptB0y
2017-10-14 11:22:57 +08:00
@Dwyanetalk 什么意思?

时间戳是不带时区信息的,但是转化成可读时间就有时区了。

比如 1514131200 这个时间戳,

2017-12-25 00:00:00 +0800
2017-12-24 16:00:00 +0000

这是两个时间是同一个时间
scriptB0y
2017-10-14 11:23:23 +08:00
@pheyer @CloudnuY 666 啊,还有这功能
pheyer
2017-10-14 11:26:15 +08:00
@scriptB0y 我说的 datetime format convert 就是 @CloudnuY 发的这个
scriptB0y
2017-10-14 11:31:15 +08:00
@pheyer 懂,可惜自带的 spotlight 好像没有
zhanghongli
2017-10-14 14:25:49 +08:00
php -r "echo date('Y-m-d H:i:s',1514131200);"
scriptB0y
2017-10-14 15:15:10 +08:00
@zhanghongli 这个太长了,不太合适。
viko16
2017-10-14 16:59:01 +08:00
就是千倍的差距,内部判断一下就好,没必要分两个函数噢...
scriptB0y
2017-10-14 17:47:33 +08:00
@viko16 项目用的 python 和 MongoDB ……

比如说我拿到一个 js 时间戳,用 js 函数判断,如果小了 1000 倍就知道自己错了。但是如果放到自动判断,就是正确的……

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/397529

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX