Dav*_*ung 72 linux macos shell date
在Linux上,您可以将"2010-10-02"之类的日期转换为shell脚本中的unix时间戳
date -d "2010-10-02" "+%s"
Run Code Online (Sandbox Code Playgroud)
由于Mac OS没有等效的-d作为日期.如何在shell脚本中将日期转换为unix时间戳.
小智 131
date +%s
Run Code Online (Sandbox Code Playgroud)
这对我在OS X Lion上运行正常.
Lou*_*nco 31
man date 在OSX上有这个例子
date -j -f "%a %b %d %T %Z %Y" "`date`" "+%s"
Run Code Online (Sandbox Code Playgroud)
我觉得你想做什么.
您可以将此用于特定日期
date -j -f "%a %b %d %T %Z %Y" "Tue Sep 28 19:35:15 EDT 2010" "+%s"
Run Code Online (Sandbox Code Playgroud)
或者使用您想要的任何格式.