Converting time from GMT to another timezone 
Author Message
 Converting time from GMT to another timezone

Hello,

I tried all possible ways to convert time from GMT to another timezone
but I could not. In particular, I'm interested in converting the
machine's clock that has the timezone defined as GMT to eastern
standard time. Is there any way to do that, on Windows?

Thanks,
Ehab



Wed, 07 Sep 2005 06:12:10 GMT  
 Converting time from GMT to another timezone

Quote:

> I tried all possible ways to convert time from GMT to another timezone
> but I could not. In particular, I'm interested in converting the
> machine's clock that has the timezone defined as GMT to eastern
> standard time. Is there any way to do that, on Windows?

What I'm wondering is what you want, other than to take time.time()
and add 5 hours to it...

Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32

Quote:
>>> import time
>>> now = time.time()
>>> now
1048285657.33
>>> time.gmtime(now)

(2003, 3, 21, 22, 27, 37, 4, 80, 0)
Quote:
>>> time.localtime(now)

(2003, 3, 21, 17, 27, 37, 4, 80, 0)
Quote:
>>> print time.gmtime.__doc__

gmtime(seconds) -> tuple

Convert seconds since the Epoch to a time tuple expressing UTC (a.k.a. GMT).

Quote:
>>> adjusted = now + 60*60*5
>>> time.localtime(adjusted)

(2003, 3, 21, 22, 27, 37, 4, 80, 0)

In effect, adding 60*60*5 lets time.localtime() produce a result which
corresponds to the result time.gmtime() produces with the unadjusted
value.

Really, it's unclear what you are trying to do.

-Peter



Wed, 07 Sep 2005 06:31:38 GMT  
 Converting time from GMT to another timezone

Quote:

> Really, it's unclear what you are trying to do.

Yet, you gave an answer.  God, it's amazing that python can even raise
one's telepathetic powers.

--

Linux solution for data management and processing.



Wed, 07 Sep 2005 07:01:20 GMT  
 Converting time from GMT to another timezone

Quote:

> Hello,

> I tried all possible ways to convert time from GMT to another timezone
> but I could not. In particular, I'm interested in converting the
> machine's clock that has the timezone defined as GMT to eastern
> standard time. Is there any way to do that, on Windows?

    import time
    now_EST = time.time() - 18000
    print time.asctime(time.gmtime(now_EST))

  Jp

Quote:

> Thanks,
> Ehab
> --
> http://mail.python.org/mailman/listinfo/python-list

--
"Pascal is Pascal is Pascal is dog meat."
                -- M. Devine and P. Larson, Computer Science 340
--
 up 1 day, 17:59, 7 users, load average: 0.03, 0.01, 0.00


Wed, 07 Sep 2005 06:38:57 GMT  
 Converting time from GMT to another timezone

Quote:


>> Really, it's unclear what you are trying to do.

> Yet, you gave an answer.  God, it's amazing that Python can even raise
> one's telepathetic powers.

Haven't followed the rest of the thread, but, in my experience,
your quip IS actually related to one way Python can help you
make better analysis.  It's a fact of life that people who are
trying to specify a program for you to write DO inevitably
express their wishes unclearly, over and over again, particularly
but not exclusively if they're not programmers.  With Python, it's
often fast and easy for you to show them several possible ways to
interpret what they've just asked for -- you throw together small
pieces of code and run them, so they can focus more accurately and
clarify their meaning.  This works better interactively and face
to face, of course -- and not at all for "waterfall" approaches
where all specs must get etched in stone before a single line of
code is written (yecch!) -- but the point is that, through this
easy exercise often repeated, you DO gradually develop your sense
for guessing the likely meaning of ambiguous requests -- AND you
stay focused on "in face of ambiguity resist the temptation to
guess", i.e., you don't blindly guess, you try at least one
sensible interpretation and SHOW it for disambiguation -- but you
NEVER omit to point out the possible misguess, so the guy who's
giving you the specs get a chance to correct himself.

Eventually you learn to use similar approaches with other languages,
too, but that may take 10 or 20 years of practice while with Python
one or two years may suffice, because it lends itself SO well to
this "interactive clarification of specifications' intentions".

So, yes, in this sense Python does "raise your telepathic powers":
you become a far more effective guesser of specifiers' intentions
in face of ambiguity, without thereby failing to point out that
there IS ambiguity and unclearness -- in part because it's so easy
to redo the code once you find out what the darn the guy DID mean.

Alex



Wed, 07 Sep 2005 16:59:45 GMT  
 Converting time from GMT to another timezone

| [...]
|     import time
|     now_EST = time.time() - 18000
|     print time.asctime(time.gmtime(now_EST))

Just being interested, these 18000, is it possible to find out how
much that is? I mean.. make a general python code that can show me the
time difference between EST and CET?

Or is it something I as developer has to look up and hardcode into my
code?

        /Andy

--
 The eye of the beholder rests on the beauty!



Wed, 07 Sep 2005 19:24:55 GMT  
 Converting time from GMT to another timezone

Quote:


> > Really, it's unclear what you are trying to do.

> Yet, you gave an answer.  God, it's amazing that Python can even raise
> one's telepathetic powers.

I think you forgot a smiley.


Wed, 07 Sep 2005 22:28:20 GMT  
 Converting time from GMT to another timezone

Quote:


> | [...]
> |     import time
> |     now_EST = time.time() - 18000
> |     print time.asctime(time.gmtime(now_EST))

> Just being interested, these 18000, is it possible to find out how
> much that is? I mean.. make a general python code that can show me the
> time difference between EST and CET?

> Or is it something I as developer has to look up and hardcode into my
> code?

Yes, sort of, and no.  I found this in rfc822.py.  It's not in any
way a complete solution, but it tells a lot.

# The timezone table does not include the military time zones defined
# in RFC822, other than Z.  According to RFC1123, the description in
# RFC822 gets the signs wrong, so we can't rely on any such time
# zones.  RFC1123 recommends that numeric timezone indicators be used
# instead of timezone names.

_timezones = {'UT':0, 'UTC':0, 'GMT':0, 'Z':0,
              'AST': -400, 'ADT': -300,  # Atlantic (used in Canada)
              'EST': -500, 'EDT': -400,  # Eastern
              'CST': -600, 'CDT': -500,  # Central
              'MST': -700, 'MDT': -600,  # Mountain
              'PST': -800, 'PDT': -700   # Pacific
              }

-Peter



Wed, 07 Sep 2005 22:31:56 GMT  
 Converting time from GMT to another timezone

Quote:


> | [...]
> |     import time
> |     now_EST = time.time() - 18000
> |     print time.asctime(time.gmtime(now_EST))

> Just being interested, these 18000, is it possible to find out how
> much that is? I mean.. make a general python code that can show me the
> time difference between EST and CET?

> Or is it something I as developer has to look up and hardcode into my
> code?

Manipulating the TZ environment variable may work, depending on
your OS:
 >>> import os
 >>> os.environ['TZ'] = 'US/Eastern'
 >>> print time.asctime(time.localtime(time.time()))
Sat Mar 22 19:06:34 2003
 >>> os.environ['TZ'] = 'UTC'
 >>> print time.asctime(time.localtime(time.time()))
Sun Mar 23 00:06:57 2003
 >>> os.environ['TZ'] = 'US/Eastern'
 >>> now = time.time()
 >>> now - time.mktime(time.gmtime(now))
-17999.518725991249

Note that if you take this approach, variables exposed by the time
module
(time.timezone, time.altzone etc.) will no longer reflect the actual
output of the functions.

Unfortunatly, there is no way to do timezone conversion stuff under Unix
that doesn't suck. Work is underway to provide these sucky ways in
Python 2.3.
Rumour has it that Windows provides a richer interface for timezone
stuff,
but it appears to be a secret.

--

http://shangri-la.dropbear.id.au/



Thu, 08 Sep 2005 08:18:04 GMT  
 Converting time from GMT to another timezone

<snip>

Quote:
> Unfortunatly, there is no way to do timezone conversion stuff under Unix
> that doesn't suck. Work is underway to provide these sucky ways in
> Python 2.3.
> Rumour has it that Windows provides a richer interface for timezone
> stuff, but it appears to be a secret.

It's a bit better, but it still sucks.  Windows will only tell you whether
daylight savings apply now, not at some other point in time.  It does
provide the current DST rules so you can apply them yourself, but those
might not be the same rules that were used in some previous year in the
same political time zone.


Sun, 11 Sep 2005 18:49:00 GMT  
 Converting time from GMT to another timezone

Quote:


>| [...]
>|     import time
>|     now_EST = time.time() - 18000
>|     print time.asctime(time.gmtime(now_EST))

That's a terrible abuse of the gmtime() function.

Quote:
> Just being interested, these 18000, is it possible to find out how
> much that is? I mean.. make a general python code that can show me the
> time difference between EST and CET?

It depends on the time of year.

Quote:
> Or is it something I as developer has to look up and hardcode into my
> code?

Please don't do that.

The best solution I can think of, within what Python provides, is
something like this:

    import sys, time

    def time_zone_convert(tm, source_zone, dest_zone):
        '''Convert a broken-down time (time.struct_time or tuple) from
        one named time zone to another.'''
        old_zone = sys.environ['TZ']
        try:
            sys.environ['TZ'] = source_zone
            stamp = time.mktime(tm)
            sys.environ['TZ'] = dest_zone
            return time.localtime(stamp)
        finally:
            sys.environ['TZ'] = old_zone

Unfortunately time zone names are not portable!  You would need to use
different names depending on the platform.



Sun, 11 Sep 2005 18:57:07 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. how to convert current time to gmt?

2. clock scan doesn't handle GMT+xxxx timezones

3. GMT time vs. local time

4. gmt vs. labview daylight saving time XL

5. GMT Time

6. gmt time again

7. Getting GMT time

8. GMT Time Conversion

9. UTC (GMT) time in VisualAge

10. UTC (GMT) time in VisualAge

11. How to make VW TimeZone use the system time zone automatically

12. how to displaying timezone independant times?

 

 
Powered by phpBB® Forum Software