Time/date conversion at the command line

When I didn’t trust my mental ability to convert dates and times, I relied on online tools like http://worldtimeserver.org/, but this task can easily be done from the command line (and without an internet connection). For instance, I am now in Taipei, and I want to know what time it will be here when it is 4:30pm in Pacific time. A quick search revealed the following use of the `date` command:

1
2
date --date='TZ="America/Los_Angeles" 2012-9-17 16:30'
Tue Sep 18 07:30:00 CST 2012

Using the date, it will also consider daylight saving’s time. Compare it with:

1
2
date --date='TZ="America/Los_Angeles" 2012-12-17 16:30'
Tue Dec 18 08:30:00 CST 2012

Now I see there is an example if the man-documentation of `date`, along with other options.

[UPDATE]

The above only converts from some other timezone to the one your shell is set to. If you want to go the other way around, you need to change the timezone (temporarily) when the command is run. For example, if you are in the Pacific timezone and want to convert a time to Singapore time, do the following (all on one line):

1
TZ=":Singapore" date --date='TZ="America/Los_Angeles" 2013-04-02 16:30'
This entry was posted in Linux. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>