Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

up vote 11 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"
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.

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.