Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Convert GMT to EST or local time

Posted on 2006-06-28
Medium Priority
Last Modified: 2012-05-05
Is there an easy way to convert GMT to say eastern within a shell script?  Can someone provide an example?

Question by:jhughes4
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
LVL 48

Expert Comment

ID: 17013953
TZ=EST date

Author Comment

ID: 17013985
ok so within a shell script how would I conver say the GMT date of 14:09 to EST?

LVL 48

Expert Comment

ID: 17014027
Do you have an existing date you want to convert, or just convert the current date?
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Author Comment

ID: 17014388
I'll be pulling the date from another application that could be current or several hours past.  The date is in a String format and I was wondering if I could take that String and pass it to something like date to have date convert it to EST or MTN, or whatever the system's time zone is.
LVL 48

Expert Comment

ID: 17014415
Can you please give an example of the format?  Do you want to retain the same format for the converted date?

Author Comment

ID: 17014541

thanks again
LVL 48

Accepted Solution

Tintin earned 2000 total points
ID: 17014669
Assuming you have GNU date, and if you don't, you should get it as it is incredibly useful for all sorts of date calculations, you can do

# Example to convert from GMT to EST
fold_date=`echo $old_date|sed 's/\(..\)\(..\)\(....\):\(.*\):...$/\3\1\2 \4/'`  # Convert date to a sensible non-ambigious format
new_date=`TZ=EST date --date "$fold_date GMT" +%m%d%Y:%T`
echo $new_date

The above example looses the milliseconds, but it's easy enough to put them back on if required.
LVL 51

Expert Comment

ID: 17026140
do you expect dates from yesterday or tomorrow (seen from your current date)?
Do you expect dates more than +/-24 hours difference?
If so I highly recommend that you use perl with Date::Manip or one of the modules from http://datetime.perl.org/

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question