2017年2月22日 星期三

[Linux 文章收集] Linux / UNIX: Convert Epoch Seconds To the Current Time

Source From Here
Question
How do I convert Epoch seconds to the current time under UNIX or Linux operating systemsUnix time, or POSIX time, is a system for describing points in time, defined as the number of seconds elapsed since midnight proleptic Coordinated Universal Time (UTC) of January 1, 1970, not counting leap seconds

How-To

Print Current UNIX Time
Type the following command to display the seconds since the epoch:
# date +"%s"
1487828286


Convert Epoch To Current Time
Type the command:
# Epoch=`date +"%s"`
# echo $Epoch
1487832372
# date -d @1487828286
Thu Feb 23 13:38:06 CST 2017
# date -d @$Epoch
Thu Feb 23 14:46:12 CST 2017

Please note that @ feature only works with latest version of date (GNU coreutils v5.3.0+). To convert number of seconds back to a more readable form, use a command like this:
# date -d @1268727836 +"%d-%m-%Y %T %z"
16-03-2010 16:23:56 +0800

AWK Example
# echo 1268727836 | awk '{print strftime("%c",$1)}'

Perl Example
# perl -e "print scalar(localtime(1268727836))"


沒有留言:

張貼留言

[Git 常見問題] error: The following untracked working tree files would be overwritten by merge

  Source From  Here 方案1: // x -----删除忽略文件已经对 git 来说不识别的文件 // d -----删除未被添加到 git 的路径中的文件 // f -----强制运行 #   git clean -d -fx 方案2: 今天在服务器上  gi...