scriptB0y

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

  •  
  •   scriptB0y · Oct 14, 2017 · 4782 views
    This topic created in 3315 days ago, the information mentioned may be changed or developed.

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

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

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

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

    屏幕快照 2017-10-14 上午 10.57.24.png

    15 replies  •  2017-10-14 17:47:33 +08:00
    lululau
    lululau
    Oct 14, 2017❤️1
    1
    Mac: date -r 1514131200
    GNU/Linux: date -d @1514131200
    siguretto
    siguretto
    Oct 14, 2017
    2
    why not `date -r` ?
    scriptB0y
    scriptB0y
    OP
    Oct 14, 2017
    3
    @lululau @siguretto

    谢谢我火星了……之前怎么没发现。。。
    oott123
    oott123
    Oct 14, 2017 via Android
    4
    其实我都是 irb
    Time.at xxx
    Dwyanetalk
    Dwyanetalk
    Oct 14, 2017
    5
    @lululau date 请问可以指定时区吗?或者 date 是根据什么判断时区的?有什么工具处理时区的问题?
    pheyer
    pheyer
    Oct 14, 2017
    6
    Mac 下有一个 alfred workflow 叫 datetime format convert 可以做这个
    CloudnuY
    CloudnuY
    Oct 14, 2017
    7
    scriptB0y
    scriptB0y
    OP
    Oct 14, 2017
    8
    @Dwyanetalk 什么意思?

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

    比如 1514131200 这个时间戳,

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

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

    比如说我拿到一个 js 时间戳,用 js 函数判断,如果小了 1000 倍就知道自己错了。但是如果放到自动判断,就是正确的……
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2198 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 13:47 · PVG 21:47 · LAX 05:47 · JFK 08:47
    ♥ Do have faith in what you're doing.