Date Time Change for a particular target Zone


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Date Time Change for a particular target Zone
# 1  
Old 05-12-2012
Date Time Change for a particular target Zone

Hi

Summary:
- Script will take 2 arguments
- Argument 1: Date/Time value in a particular format
- Argument 2: TimeZone value

Code:
Examples:
Argument 1: 
a. "May 11, 2012 08:00:00 AM"
b. "Dec 21, 2012 12:21:12 PM"
c. "Oct 2, 2012 05:00:00 PM"

Argument 2:
a. MT or MST or MDT
b. ET
c. PT or PCT
d. GMT / UTC
e. CT 
d. IST

Where MT is Mountain time, ET is Eastern Time, PT Pacific Time, GMT is Greenwich Mean Time, CT Central time, IST Indian Standard Time... etc etc.

-----------

Now,
What I need is a BASH script to do the following:

The script will take Argument 1 and Argument 2 and convert the Date/Time in the same Date/Time format to GMT time zone.

i.e.

A.
If I'm entering:
$ Script.sh "May 12, 2012 10:00:00 AM" MT
then, 
script should return me GMT value as:
"May 12, 2012 04:00:00 PM"

NOTE: In Daylight/Standard time period, this value can 
change.

B.
If I'm entering: 
$ Script.sh "May 12, 2012 10:00:00 AM" ET
then, 
script should return me GMT value as:
"May 12, 2012 02:00:00 PM" or 

-- whatever is the correct value for this ET is for GMT 
time zone.



C.
If I'm entering: 
$ Script.sh "May 12, 2012 11:00:00 PM" IST
then, 
script should return me GMT value as:
"May 12, 2012 05:30:00 PM"

as IST is +5h:30m ahead of GMT.

# 2  
Old 05-12-2012
GNU date has an -u option to return UTC (GMT) time. Then just specify the time zone with the date and time:
Code:
$ date -u -d 'May 12, 2012 11:00:00 PM IST'
Sat May 12 17:30:00 UTC 2012

# 3  
Old 05-12-2012
Hi,

I can achieve it without -u option.Please let me know if I am doing wrong

Code:
[stpuser@VHLDV001 ~]$ date "+%B %e, %Y %X" -u -d 'May 12, 2012 11:00:00 PM CST'
May 13, 2012 05:00:00 AM
[stpuser@VHLDV001 ~]$ date "+%B %e, %Y %X"  -d 'May 12, 2012 11:00:00 PM CST'
May 13, 2012 05:00:00 AM
[stpuser@VHLDV001 ~]$ date "+%B %e, %Y %X" -d 'May 12, 2012 11:00:00 PM CST'
May 13, 2012 05:00:00 AM
[stpuser@VHLDV001 ~]$ date "+%B %e, %Y %X" -d 'May 12, 2012 11:00:00 PM IST'
May 12, 2012 05:30:00 PM
[stpuser@VHLDV001 ~]$ date "+%B %e, %Y %X" -d 'May 12, 2012 11:00:00 AM IST'
May 12, 2012 05:30:00 AM
[stpuser@VHLDV001 ~]$ date "+%B %e, %Y %X" -d 'May 12, 2012 11:00:00 AM MDT'
May 12, 2012 05:00:00 PM

# 4  
Old 05-12-2012
That happens to work only because your local timezone is UTC. I am in PST, and so I get
Code:
$ date "+%B %e, %Y %X" -d 'May 12, 2012 11:00:00 AM MDT'
May 12, 2012 10:00:00 AM

If you use -u, it will be independent on your local timezone.
# 5  
Old 05-12-2012
Thanks for your support and valuable advise
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Date and time change in global and non global zone

Hi, If I change date and time in global zone, then it will affect in non global zones. During this process what files will get affect in non global zones and which mechanism it's using to change. gloabl zone:Solaris 11.3 X86 TIA (1 Reply)
Discussion started by: Sumanthsv
1 Replies

2. UNIX for Dummies Questions & Answers

How to change the time zone in UNIX??

hi, my system date and time zone is PDT. whenever i append date time stamp to a file it appends the system date thats PDT date time zone. i want to append GMT time zone. is there a mechanism or option which can append the date time stamp according to GMT. (4 Replies)
Discussion started by: Little
4 Replies

3. AIX

Change Time Zone to UTC without DST

Hello AIX friends, We have timezone settings on our AIX 6.1 boxes set to Europe/London. How can I change it to UTC timezone with Daylight saving disabled. After running "smit chtz_user" I don't see UTC option in the listing. Please advise. TIA (3 Replies)
Discussion started by: prvnrk
3 Replies

4. Solaris

modifying date and time and time zone on solaris 5.10 with (redundant server) veritas

I have a cluster of two Solaris server (veritas cluster). one working and the other is standby I am going to change the date on them , and am looking for a secure solution as it is giving an important service. my opinion is that the active one doesn't need to be restarted (if I don't change the... (1 Reply)
Discussion started by: barry1946
1 Replies

5. AIX

Bug in AIX 6.1/7.1 Time Zone DST Change -again

Hi Everyone Just wanted to share with you that IBM AIX is having again problem with Summer Time Shift.. IBM Possible Action Required: System time may not change properly at DST start/end dates on AIX 7.1 and AIX 6.1 - United States For me it means some additional overtimes in the... (0 Replies)
Discussion started by: gito
0 Replies

6. Shell Programming and Scripting

Getting date output based on time zone

Hi, We have a server in US and hence while the command "date" is given it gives the output in EDT. If I want the date output in MET, how can I get it. Please let me know how I could do it in the script which is ksh. Thanks. (1 Reply)
Discussion started by: jmathew99
1 Replies

7. Homework & Coursework Questions

Date comparison with 'string date having slashes and time zone' in Bash only

1. The problem statement, all variables and given/known data: I have standard web server log file. It contains different columns (like IP address, request result code, request type etc) including a date column with the format . I have developed a log analysis command line utility that displays... (1 Reply)
Discussion started by: TariqYousaf
1 Replies

8. HP-UX

How can I change in HP-UX to Jerusalem time zone

How can I change in HP-UX The time zone to reflect the Jerusalem/Israel time zone (I think ist called IDT or IST) ? tnx (5 Replies)
Discussion started by: umen
5 Replies

9. HP-UX

Time Zone Change Needed

Need help with a timezone change for my user profile on HPUX, from UTC to PDT8PST pgop:/home/pgop > date Thu Sep 25 15:09:50 UTC 2008 to Thu Sep 25 08:12:44 PDT 2008 Tried looking through manuals for date over this to no luck!! :confused: (3 Replies)
Discussion started by: pgop
3 Replies

10. UNIX for Advanced & Expert Users

Change params for time zone

Hi! How ican change parameters for daylight, i mean, i want change the daylight on december first week. I've tried with /usr/lib/tztab but result unsuccessful. (7 Replies)
Discussion started by: agustincm
7 Replies
Login or Register to Ask a Question