Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Getting GMT time

29 views
Skip to first unread message

Anonymous AtWork

unread,
Dec 29, 2005, 2:56:08 PM12/29/05
to
I want to know what the GMT time is. If I do [clock seconds], I get the
local time. I can add 5 hours, but what about DST when it is 6 (or
4--whatever the difference is). There's probably some kind of
non-portable craziness I could do to find out what TZ the computer is in
and figure out the local algorithm for adjustment thereof, but since Tcl
already knows all that (right?) it seems like it could do it for me.

Is there a simple, 2-3 line way to do this?

Bryan Oakley

unread,
Dec 29, 2005, 3:03:20 PM12/29/05
to

Look at the clock man page, especially where it mentions the -gmt option
to "clock format".

Anonymous AtWork

unread,
Dec 29, 2005, 3:22:05 PM12/29/05
to

That will *format* the number of seconds I have as a GMT time. But the
number of seconds I have isn't GMT, it's local. Given the local time, I
want to know the GMT time.

Gerald W. Lester

unread,
Dec 29, 2005, 3:40:34 PM12/29/05
to

Why in the world would you think the seconds returned by [clock seconds] is
local?

BTW, did you even try what Bryan suggested?

Bryan Oakley

unread,
Dec 29, 2005, 4:04:34 PM12/29/05
to
Anonymous AtWork wrote:
> Bryan Oakley wrote:
>
>> Anonymous AtWork wrote:
>>
>>> I want to know what the GMT time is. ...

>>> Is there a simple, 2-3 line way to do this?
>>
>> Look at the clock man page, especially where it mentions the -gmt
>> option to "clock format".
>>
>
> That will *format* the number of seconds I have as a GMT time. But the
> number of seconds I have isn't GMT, it's local. Given the local time, I
> want to know the GMT time.

The only difference in time between here (pick your own definition for
"here) and GMT is the formatting, so I'm not sure what you're asking.

How is what I suggested not what you want? Does the following code print
something that is unexpected for you?

% set now [clock seconds]
1135889846
% clock format $now
Thu Dec 29 14:57:26 -0600 2005
% clock format $now -gmt 1
Thu Dec 29 20:57:26 +0000 2005

Donal K. Fellows

unread,
Dec 29, 2005, 6:48:12 PM12/29/05
to
Gerald W. Lester wrote:
> Why in the world would you think the seconds returned by [clock seconds]
> is local?

You do know that Microsoft Windows has been making that mistake for
years? Tcl tries very hard to paper over the fact FWIW (there are some
ugly edge cases though.)

Donal.

sleb...@gmail.com

unread,
Dec 29, 2005, 7:35:21 PM12/29/05
to

You didn't try it did you? It works as expected:

% clock format [clock seconds]
Fri Dec 30 8:31:45 AM Malay Peninsula Standard Time 2005
% clock format [clock seconds] -gmt 1
Fri Dec 30 12:31:48 AM GMT 2005

>From the results I got, since Malaysian time is GMT+8, it looks like it
works (8:31 AM here means it's 31 minutes past midnight GMT).

Anonymous AtWork

unread,
Dec 30, 2005, 7:47:29 AM12/30/05
to

Sorry, I was incredibly unclear, mostly because I didn't even know what
I wanted.

[clock seconds] returns a number of seconds. I format those seconds to
my local timezone. Then I remove the TZ designation and pretend that it
is a GMT time. I turn that GMT time into a number of seconds.

Obviously I can do this with string manipulation, I was just wondering
if there was a to do it with [clock], like if it could return how many
seconds from GMT my localtime is. But now that I lay it all out like
that, I realize just how ugly this is (it was a workaround to another
problem). I've since just fixed the issue I was trying to work around
in the first place.

Sorry, everyone!

Stefaan

unread,
Dec 31, 2005, 6:06:16 AM12/31/05
to

I use following algoritm to determine the GMT time to calculate planet
positions

## let t be the local time
set t [clock seconds]
1136026469

clock format $t -format "%Y-%m-%d %H:%M:%S"
2005-12-31 11:54:29
## Belgium is GMT+1

clock format $t -format "%Y-%m-%d %H:%M:%S" -gmt 1
2005-12-31 10:54:29

## Following command will convert the local time t to GMT time

clock scan [clock format $t -format "%Y-%m-%d %H:%M:%S" -gmt 1]
1136022869

Kevin Kenny

unread,
Dec 31, 2005, 10:51:38 AM12/31/05
to
Stefaan wrote:
> I use following algoritm to determine the GMT time to calculate planet
> positions
[snip]

> ## Following command will convert the local time t to GMT time
>
> clock scan [clock format $t -format "%Y-%m-%d %H:%M:%S" -gmt 1]
> 1136022869

That is just plain wrong.

Whatever you might believe, [clock seconds] returns the number of
nominal seconds since 00:00 UTC, 1 January 1970. There is no such
thing as "local seconds" in Tcl. All time zone conversion happens
inside [clock scan] and [clock format]. If [clock seconds] reports
time in the local time zone and not UTC, that is a bug. (Nobody
has reported such a bug - and since I'm the mainainer of [clock],
I'd surely know if anyone had.)


--
73 de ke9tv/2, Kevin

Stefaan

unread,
Dec 31, 2005, 12:26:05 PM12/31/05
to

OK, I shouldn't have set the starting value with [clock seconds]. But if
the starting value represents a local time, not obtained from TCL
build-in commands, then in my opinion the algoritm works.

0 new messages