Can I get UTC offset from Unix command line?

ID : 274377

viewed : 25

Tags : unixcommand-lineutcautoconfunix

Top 4 Answer for Can I get UTC offset from Unix command line?

vote vote


Try this, and see whether it works for you:

date +%z 
vote vote


For others doing ISO8601, you might pick some variant of:

date +%Y%m%dT%H%M%S%z     # 20140809T092143-0700 date -u +%Y%m%dT%H%M%S%z  # 20140809T162143+0000 date -u +%Y%m%dT%H%M%SZ   # 20140809T162143Z 

I like those because the lack of punctuation supports universal use. Note that the capital Z is 'hard-coded' for UTC - using %Z will put UTC or the other named timezone. If you prefer punctuation:

date +%Y-%m-%dT%H:%M:%S%z      # 2014-08-09T09:21:43-0700 date +%Y-%m-%dT%H:%M:%S%:z     # 2014-08-09T09:21:43-07:00 - NOT ALL SYSTEMS date -u +%Y-%m-%dT%H:%M:%S%z   # 2014-08-09T16:21:43+0000 date -u +%Y-%m-%dT%H:%M:%S%:z  # 2014-08-09T16:21:43+00:00 - NOT ALL SYSTEMS date -u +%Y-%m-%dT%H:%M:%SZ    # 2014-08-09T16:21:43Z 

Consult man strftime as supported formats vary. For instance, some systems support inserting colons into the offset using %:z, %::z, or %:::z - only two of my five systems do (Debian, Ubuntu do, but Mac, BusyBox, QNX do not).

And I often go back to for reference.

vote vote


Yes, date can do this:

[tomalak@lolphin:~] date -R Mon, 02 May 2011 17:37:45 +0100 

Or, more specifically:

[tomalak@lolphin:~] date -R | awk '{print $6}' +0100 [tomalak@lolphin:~] date +%z +0100 

Reading date --help is very useful.

vote vote


Top 3 video Explaining Can I get UTC offset from Unix command line?