2013-02-22 146 views
2

如何从unix时间戳bash下如何从Unix时间戳设置日期/时间在bash

[email protected] />date 
Thu Jan 1 00:10:49 UTC 1970 
[email protected] />date +%s 
652 
[email protected] />date +%s -s "`date +%s`" 
date: invalid date `662' 

设定的日期/时间,因为你可以看到日期+%S -s“2323123”不工作:/

[解决] ..under bash中我可以使用

date +%s -s "@`date +%s`" 

date -s @1361529589 

谢谢!

问题2如何在busybox下实现这个功能?

[email protected] />date -s @1361529589 
date: invalid date `@1361529589' 

也许有办法像

echo '1361529589' > /dev/unix_time_stamp_or_whatever ? :) 

回答

4

您需要用@符号的前缀号码,以便在date命令知道它代表数量为seconds since the Epoch。试试这个:

date +%s -s @`date +%s` 
+1

它的工作原理! ......但只能在bash之下 - 就像问。如何在busybox下完成此操作? ..更新我的问题 – luzik 2013-02-22 10:43:13

3

使用这样的事情:

date -s @435456646