Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set date/time from unix timestamp under bash [closed]

How to set date/time from unix timestamp under bash

root@M501 />date
Thu Jan  1 00:10:49 UTC 1970
root@M501 />date +%s
652
root@M501 />date +%s -s "`date +%s`"
date: invalid date `662'

as You can see date +%s -s "2323123" do not work :/

[SOLVED] ..under bash i can use

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

or

date -s @1361529589

Thanks!

Question #2 How to achieve this under busybox?

root@M501 />date -s @1361529589
date: invalid date `@1361529589'

maybe there is way like

echo '1361529589' > /dev/unix_time_stamp_or_whatever ? :)
like image 711
luzik Avatar asked Sep 14 '25 08:09

luzik


2 Answers

You need to prefix the number with the @ symbol so that the date command knows that it represents the number of seconds since the Epoch. Try this:

date +%s -s @`date +%s`
like image 162
dogbane Avatar answered Sep 17 '25 00:09

dogbane


Use something like this:

date -s @435456646
like image 28
Amin Mozafari Avatar answered Sep 17 '25 01:09

Amin Mozafari