7

I want to set date from a seconds since epoch value, for instance I want to set date with input value 1452053571.

I read through date -help but not found anything.

Is there any parameters to do it?

5
  • 1
    You did not read carefully, try date --date='@2147483647'
    – cuonglm
    Jan 6 '16 at 4:23
  • @cuonglm Thank you, I mean How to set ? Jan 6 '16 at 4:25
  • Ok, sudo date -s "$(date --date='@2147483647')" :) Jan 6 '16 at 4:28
  • Just simple, date -s '@2147483647'. Please reword+reformat your question to make it more clear.
    – cuonglm
    Jan 6 '16 at 4:37
  • @cuonglm Post an answer and I will mark it. Jan 6 '16 at 4:44
14

With GNU date, you can use the same date string format for both -d and -s options.

To convert from seconds since epoch to human readable format:

date -d '@2147483647'

To set it:

date -s '@2147483647'

With *BSD date:

# Convert seconds since epoch
$ date -r 2147483647 
Tue Jan 19 03:14:07 UTC 2038

# Set date by seconds since epoch
$ date "$(date -r 2147483647 +'%y%m%d%H%M.%S')"
Tue Jan 19 03:14:07 UTC 2038
1
  • Such a strange thing that BSD does not simply allow to use Epoch as direct input. Mar 2 '19 at 15:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.