11
4
How can I convert a date/time string, e.g. 2011-11-13 08:11:02 +0000
, to my local time zone on the command line?
11
4
How can I convert a date/time string, e.g. 2011-11-13 08:11:02 +0000
, to my local time zone on the command line?
17
Use date -jf "<input format>" "<input value>" +"<output format>"
.
The following converts a UTC date to my local time zone (CET):
$ date -jf "%Y-%m-%d %H:%M:%S %z" "2011-11-13 08:11:02 +0000" +"%Y_%m_%d__%H_%M_%S"
2011_11_13__09_11_02
If you specify the same date format for both input and output, you will only convert the time to your local time zone. But, as in the example, you can combine that with a format conversion.
2The target time zone can be changed by temporarily setting $TZ
: TZ=EST date -jf %H%z 23+0100 +%I%p
→ 05PM
– Lri – 2011-11-13T20:07:29.550
Don't hesitate to add different answers, but please remember that OS X has BSD
date
, not GNUdate
. The options are quite different. – Daniel Beck – 2011-11-13T08:45:11.993