ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
Rep:
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.
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:
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!
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.