如何将yyyy-mm-dd hh:mm:ss中的日期转换为Unix纪元时间 [英] How to convert a date in yyyy-mm-dd hh:mm:ss to unix epoch time

查看:84
本文介绍了如何将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)}'

这篇关于如何将yyyy-mm-dd hh:mm:ss中的日期转换为Unix纪元时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆