1

I've got an arbitrary time stamp 1427792481 I'm trying to implement +"%F" so I just get 2015-03-31 How can I do this? My ideal goal would be to get 20150331

2

You can try this:

date -d @1427792481 +"%F"

or for 20150331:

date -d @1427792481 +"%Y%m%d"
3

My ideal goal would be to get 20150331

date -d @1427792481 +"%Y%m%d"
2

A few options:

  • ksh93 or recent bash, any system (shell builtin):

    printf "%(%Y%m%d)T\n" 1427792481
    
  • zsh any system (builtin):

    zmodload zsh/datetime
    strftime %Y%m%d 1427792481
    
  • GNU date:

    date -d@1427792481 +%Y%m%d
    
  • GNU awk:

    awk 'BEGIN{print strftime("%Y%m%d", 1427792481)}'
    
  • perl:

    perl -MPOSIX -le 'print strftime "%Y%m%d", localtime 1427792481'
    

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.