0%

命令行时间戳与时间转换

Linux

1
date -d @<timestamp>

macOS / FreeBSD

1
date -r <timestamp>

PowerShell

1
[datetime]::UnixEpoch.AddSeconds(<timestamp>)

Zsh

1
strftime '%Y-%m-%d %H:%M:%S' <timestamp>

Python

1
python3 -c "import sys, time; print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(int(sys.argv[1]))))" <timestamp>

Perl

1
perl -MPOSIX -le 'print strftime "%Y-%m-%d %H:%M:%S", localtime($ARGV[0])' <timestamp>

Ruby

1
ruby -e 'puts Time.at(ARGV[0].to_i).strftime("%Y-%m-%d %H:%M:%S")' <timestamp>

Groovy

1
groovy -e "println new Date(args[0] as long).format('yyyy-MM-dd HH:mm:ss')" <timestamp>

Node

1
node -e "console.log(new Date(parseInt(process.argv[1])).toLocaleString())" <timestamp>