Solved

Convert GMT to EST or local time

Posted on 2006-06-28
8
21,745 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
ID: 17013953
TZ=EST date
0
 

Author Comment

by:jhughes4
ID: 17013985
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
ID: 17014027
Do you have an existing date you want to convert, or just convert the current date?
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

Author Comment

by:jhughes4
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.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 17014415
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
ID: 17014541
06292006:23:31:57:580
mmddyyyy:HH:MM:SS:MS

thanks again
0
 
LVL 48

Accepted Solution

by:
Tintin earned 500 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

#!/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
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/
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
change HISTFILE for root user on AIX 3 81
Parsing a file using ksh 10 65
help pulling data string using Awk 9 72
How to Insert a File Using Text Editor 9 90
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…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
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.:
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…

832 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