LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-06-2009, 02:12 PM   #16
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043

Code:
jlinkels@jlinkels-lt:~$ date --utc -d "2007-02-04 13:30:00 GMT-10 hours"
Sun Feb  4 03:30:00 UTC 2007
jlinkels@jlinkels-lt:~$ date --utc -d "2007-02-04 13:30:00 CET"
Sun Feb  4 12:30:00 UTC 2007
I am not sure what date does when you enter the TLA for GMT+10, but if you take the effort to enter GMT-10 hours in the date string it gives the correct UTC time.

Using the TLA for CET (GMT-1) does work.

jlinkels
 
1 members found this post helpful.
Old 03-06-2009, 02:53 PM   #17
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
Quote:
Originally Posted by jlinkels View Post
Code:
jlinkels@jlinkels-lt:~$ date --utc -d "2007-02-04 13:30:00 GMT-10 hours"
Sun Feb  4 03:30:00 UTC 2007
jlinkels@jlinkels-lt:~$ date --utc -d "2007-02-04 13:30:00 CET"
Sun Feb  4 12:30:00 UTC 2007
I am not sure what date does when you enter the TLA for GMT+10, but if you take the effort to enter GMT-10 hours in the date string it gives the correct UTC time.

Using the TLA for CET (GMT-1) does work.
jlinkels
Inspired by this, I came up with a one-line bash script that will entirely replace my Perl script.
Code:
date --utc -d "$* GMT-10 hours" +'%F %T'
I know, it says GMT-10 instead of GMT+10, but it does work for translating GMT+10 to UTC.

If, say, you store that one-line shell script as xxx in a directory in your $PATH, you'll see output like this:
Code:
wally:~/thursday/2$ xxx 2009-01-25 20:57:22
2009-01-25 10:57:22
wally:~/thursday/2$ xxx 2009-01-25 10:57:22
2009-01-25 00:57:22
wally:~/thursday/2$ xxx 2009-01-25 00:57:22
2009-01-24 14:57:22
wally:~/thursday/2$
 
1 members found this post helpful.
Old 03-06-2009, 03:15 PM   #18
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
Quote:
Originally Posted by wje_lq View Post
I know, it says GMT-10 instead of GMT+10, but it does work for translating GMT+10 to UTC.
I never understood why that is. I live in an unnamed time zone where it is 4 hours earlier than GMT. Still I have to enter GMT+4 as my time zone.

jlinkels
 
1 members found this post helpful.
Old 03-06-2009, 05:01 PM   #19
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
Quote:
I never understood why that is. I live in an unnamed time zone where it is 4 hours earlier than GMT. Still I have to enter GMT+4 as my time zone.
This is indeed puzzling. I tried a similar experiment. I'm in California, whose time is (at this time of year) eight hours earlier than UTC. But:
Code:
wally:~$ echo $TZ

wally:~$ date
Fri Mar  6 14:58:20 PST 2009
wally:~$ export TZ=GMT+8
wally:~$ date
Fri Mar  6 14:58:33 GMT 2009
wally:~$ export TZ=GMT-8
wally:~$ date
Sat Mar  7 06:58:40 GMT 2009
wally:~$ export TZ=GMT+10
wally:~$ date
Fri Mar  6 12:58:49 GMT 2009
wally:~$ export TZ=GMT-10
wally:~$ date
Sat Mar  7 08:58:55 GMT 2009
wally:~$ export TZ=UTC
wally:~$ date
Fri Mar  6 22:59:07 UTC 2009
wally:~$
So, hattori.hanzo, you think that just because you're in Australia, you're at GMT+10? I would have thought so, too, but our computer overlords know different! Look at the above output, look at the final few lines, and you'll see you're really at GMT-10!
 
1 members found this post helpful.
Old 06-02-2013, 09:28 PM   #20
hattori.hanzo
Member
 
Registered: Aug 2006
Posts: 168

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by wje_lq View Post
Inspired by this, I came up with a one-line bash script that will entirely replace my Perl script.
Code:
date --utc -d "$* GMT-10 hours" +'%F %T'
I know, it says GMT-10 instead of GMT+10, but it does work for translating GMT+10 to UTC.

If, say, you store that one-line shell script as xxx in a directory in your $PATH, you'll see output like this:
Code:
wally:~/thursday/2$ xxx 2009-01-25 20:57:22
2009-01-25 10:57:22
wally:~/thursday/2$ xxx 2009-01-25 10:57:22
2009-01-25 00:57:22
wally:~/thursday/2$ xxx 2009-01-25 00:57:22
2009-01-24 14:57:22
wally:~/thursday/2$
I had been using your perl code in my script since my last post in this thread. :-) Just researching on how to speed things up. The time conversion process from local time to UTC is taking too long for the amount of lines I am processing.

I might look into testing:

Code:
date --utc -d "$* GMT0-10 hours" +'%F %T'
Cheers
 
  


Reply

Tags
timezone, tz, utc



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert a index.htm into single clear list of http:// links frenchn00b Programming 6 10-30-2007 04:48 AM
How to convert between list<T>::iterator and T* shreks Programming 2 08-26-2004 05:27 PM
my clock is UTC??? mathfeel Linux - General 2 08-16-2002 08:42 PM
Convert mailing list to forum fend88 Linux From Scratch 1 05-24-2002 06:17 AM
Timestamps Config Programming 2 04-22-2002 02:07 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration