如何在MacOS的shell脚本中将DATE转换为UNIX TIMESTAMP [英] How to convert DATE to UNIX TIMESTAMP in shell script on MacOS

查看:167
本文介绍了如何在MacOS的shell脚本中将DATE转换为UNIX TIMESTAMP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Linux上,您可以通过

On Linux you can convert a date like "2010-10-02" to a unix timestamp in shell script by

date -d "2010-10-02" "+%s"

由于Mac OS没有日期的等效 -d 。如何在shell脚本中将日期转换为unix时间戳。

Since Mac OS does not have the equivalent -d for date. How do you go about converting a date to a unix timestamp in a shell script.

推荐答案

man date在这个例子中,这个例子

date -j -f "%a %b %d %T %Z %Y" "`date`" "+%s"

想。

您可以在特定日期使用此功能

You can use this for a specific date

date -j -f "%a %b %d %T %Z %Y" "Tue Sep 28 19:35:15 EDT 2010" "+%s"

或使用您想要的任何格式。

Or use whatever format you want.

这篇关于如何在MacOS的shell脚本中将DATE转换为UNIX TIMESTAMP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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