Re: Getting GMT time



Anonymous AtWork wrote:
Bryan Oakley wrote:

Anonymous AtWork wrote:

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?



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.

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
.



Relevant Pages

  • Re: CF 1 Setting time across Daylight Saving Boundary Issue
    ... I've just run through a simple test where I send a new local time (local ... account for the DST change and changing the DST flag returned by ... it's probably caching the DST flag and, therefore, using the wrong offset to ... I do SetSystemTimeall over the place and the clock is always fine. ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: system clock is too slow
    ... >> the clock hasn't been saved to the hardware clock. ... > DST) is then just an OS setting. ... > and do the offset yourself when you need local time). ... One subtlety I just discovered is that in Windows, ...
    (Fedora)
  • Re: NTP Configuration for DST?
    ... OpenVMS systems usually have the system clock set to local ... The time NTPD comes up with is converted to local time (using ... We do this using zone and DST information already present in our ...
    (comp.protocols.time.ntp)
  • Re: hware clock left bad after a system failure
    ... >> really have disk or driver problems at all. ... when in fact I run a local time ... but if the system is set to run its hardware clock on grenwich ... I *think* the problem is that the assumption of grenwich time is only ...
    (Linux-Kernel)
  • Re: how to change date of system
    ... time for DST, and ending up an hour out? ... Linux doesn't do that. ... the world that observe DST (at least for those who set their HW clock to ... local time), and I'm sure that's *not* what you mean. ...
    (Debian-User)