Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
Don't hesitate to add different answers, but please remember that OS X has BSD date, not GNU date. The options are quite different. – Daniel Beck Nov 13 '11 at 8:45
up vote 12 down vote accepted

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"

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.

share|improve this answer
The target time zone can be changed by temporarily setting $TZ: TZ=EST date -jf %H%z 23+0100 +%I%p05PM – user495470 Nov 13 '11 at 20:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .