1

I had this working on Ubuntu but I'm now trying to run the script on OSX but it seems that the formatting of date is different.

Originally I had:

date -d "$MODDATE" +%F" "%H":"%M

where $MODDATE is a unix timestamp generated with stat

However the above date function doesn't work the same way on BSD versions. How can I convert the timestamp to the date in the following format: YYYY-MM-DD HH:MM ?

  • In what format is $MODDATE? There are plenty of different stat commands that can produce a variety of formats. If you can get it in number of seconds from the epoch, do that. – Gilles Aug 12 '13 at 23:47
3

You can use the command:

$ date -jf "<input format>" "<input value>" +"<output format>"

For example:

$ date -jf "%Y-%m-%d %H:%M" "2011-11-13 08:11:02" +"%Y-%m-%d %H:%M"
2013-08-13 09:11

References

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.