How to set date/time from unix timestamp under bash

11,268

Solution 1

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`

Solution 2

Use something like this:

date -s @435456646
Share:
11,268

Related videos on Youtube

luzik
Author by

luzik

Updated on September 15, 2022

Comments

  • luzik
    luzik over 1 year

    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 ? :)
    
  • luzik
    luzik about 11 years
    it works! ...but only under bash - as asked. How to achive this under busybox? ..updating my question