如何在脚本中将日期从Unix时间转换为字符串? [英] How do I convert a date from Unix time to string, in a script?

查看:44
本文介绍了如何在脚本中将日期从Unix时间转换为字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要将日期从字符串转换为Unix时间,我可以使用 date --date"2012-02-13" +%s .

To convert a date from string to Unix time, I can use date --date "2012-02-13" +%s.

从Unix时间到字符串,我该如何做相反的事情?

How do I do the opposite, from Unix time to string?

推荐答案

您可以使用 date --date @datetime :

[foo@bar ~]$date --date "2012-02-13" +%s
1329055200
[foo@bar ~]$date --date @1329055200
Mon Feb 13 00:00:00 EST 2012
[foo@bar ~]$date --date @1329055200 +"%Y-%m-%d"
2012-02-13

我不确定'@xxxx'的记录位置!

I'm not sure where the '@xxxx' is documented though!

这篇关于如何在脚本中将日期从Unix时间转换为字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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