Get current time in seconds since the Epoch on Linux, Bash

前端 未结 7 1494
长发绾君心
长发绾君心 2020-12-02 03:42

I need something simple like date, but in seconds since 1970 instead of the current date, hours, minutes, and seconds.

date doesn\'t seem t

相关标签:
7条回答
  • 2020-12-02 04:20

    use this bash script (my ~/bin/epoch):

    #!/bin/bash
    
    # get seconds since epoch
    test "x$1" == x && date +%s && exit 0
    
    # or convert epoch seconds to date format (see "man date" for options)
    EPOCH="$1"
    shift
    date -d @"$EPOCH" "$@"
    
    0 讨论(0)
提交回复
热议问题