Sunday, April 3, 2011

How can I format date -u so that the results include timezone offset in a Mac OSX terminal session?

In a terminal session I can use date -u to get
Mon Mar 16 03:34:39 2009 UTC
However, I'd like to include the offset. I'm modifying a TextMate tab trigger so that I can insert the full date including the local offset, in standard UTC format. I believe that would be in the following form: Mon Mar 16 03:34:39 2009 UTC -0500

So, as you can see, I don't know how to get the timezone offset and combine that with formatted date results.

From stackoverflow
  • Try this:

    echo `date -u` `date +%z`
    
    mouviciel : Replaced date -u +%z by date +%z. the first one would always return +0000.
    John Feminella : Whoops, good catch. Thanks for the fix.
    Michael Prescott : That's perfect, thank you very much!

0 comments:

Post a Comment