如何将yyyy-mm-dd hh:mm:ss中的日期转换为Unix纪元时间
问题描述:
我的日期格式如2016-02-26 14:12:36.,我必须将其转换为Unix纪元时间.我可以选择使用命令:date +%s将当前时间转换为纪元时间,但是如何将特定日期转换为纪元unix时间
I have date format like 2016-02-26 14:12:36., I have to convert it into unix epoch time. I have the option to convert current time to epoch time using command : date +%s, however how to convert a specific date to epoch unix time
答
像这样从日期开始,您可以获得自纪元以来的秒数,
You can get seconds since the epoch from date like this ,
$ SECFROMEPOCH=`date --date="2016-02-26 14:12:36" +%s`
然后您可以像这样检查日期返回给您的值,
And then you can check the value that date gave back to you like this,
$ echo $SECFROMEPOCH | awk '{print strftime("%c",$1)}'