Solved

Convert GMT to EST or local time

Posted on 2006-06-28
8
21,732 Views
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?

thanks
0
Comment
Question by:jhughes4
  • 4
  • 3
8 Comments
 
LVL 48

Expert Comment

by:Tintin
Comment Utility
TZ=EST date
0
 

Author Comment

by:jhughes4
Comment Utility
ok so within a shell script how would I conver say the GMT date of 14:09 to EST?

thanks
0
 
LVL 48

Expert Comment

by:Tintin
Comment Utility
Do you have an existing date you want to convert, or just convert the current date?
0
 

Author Comment

by:jhughes4
Comment Utility
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.
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 48

Expert Comment

by:Tintin
Comment Utility
Can you please give an example of the format?  Do you want to retain the same format for the converted date?
0
 

Author Comment

by:jhughes4
Comment Utility
06292006:23:31:57:580
mmddyyyy:HH:MM:SS:MS

thanks again
0
 
LVL 48

Accepted Solution

by:
Tintin earned 500 total points
Comment Utility
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

#!/bin/sh
# Example to convert from GMT to EST
old_date='06292006:23:31:57:580'
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.
0
 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
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/
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

762 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now