How to obtain GMT offset?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • new pip

    #1

    How to obtain GMT offset?

    I'm using Windows os. If the current system date time is '28 Jun 2001
    14:17:15 +0700', how can I obtain the value '+0700' using python?

    Thank you
  • Erik Max Francis

    #2
    Re: How to obtain GMT offset?

    new pip wrote:
    [color=blue]
    > I'm using Windows os. If the current system date time is '28 Jun 2001
    > 14:17:15 +0700', how can I obtain the value '+0700' using python?[/color]

    time.timezone gives you the timezone offset in minutes.

    --
    Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/
    San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
    Many would be cowards if they had courage enough.
    -- Thomas Fuller

    Comment

    • John Machin

      #3
      Re: How to obtain GMT offset?

      new pip wrote:[color=blue]
      > I'm using Windows os. If the current system date time is '28 Jun 2001
      > 14:17:15 +0700', how can I obtain the value '+0700' using python?[/color]


      If the current system date is in 2001, obtaining "GMT offset" is the
      least of your concerns :-)

      Have you read the section on the time module in the Python manual?
      If so, what didn't you understand?

      One or more of the following might assist:
      [color=blue][color=green][color=darkred]
      >>> import time
      >>> time.gmtime(), time.localtime( )[/color][/color][/color]
      ((2005, 8, 16, 3, 59, 3, 1, 228, 0), (2005, 8, 16, 13, 59, 3, 1, 228, 0))[color=blue][color=green][color=darkred]
      >>> time.timezone[/color][/color][/color]
      -36000[color=blue][color=green][color=darkred]
      >>>[/color][/color][/color]

      Looks like it's '-1000' (hours) for me at the moment. Daylight saving
      saving isn't operating here at the moment, so I can't tell whether that
      makes a difference. I haven't tried to understand the bits about DST in
      the manual, but maybe you should.


      HTH,
      John

      Comment

      • Magnus Lycka

        #4
        Re: How to obtain GMT offset?

        new pip wrote:[color=blue]
        > I'm using Windows os. If the current system date time is '28 Jun 2001
        > 14:17:15 +0700', how can I obtain the value '+0700' using python?
        >
        > Thank you[/color]

        If you ignore the time and datetime modules, you can always split
        the string on whitespace and grab the last part:
        [color=blue][color=green][color=darkred]
        >>> ts='28 Jun 2001 14:17:15 +0700'
        >>> tz=ts.split()[-1]
        >>> print tz[/color][/color][/color]
        +0700

        Comment

        • Peter Hansen

          #5
          Re: How to obtain GMT offset?

          Erik Max Francis wrote:[color=blue]
          > time.timezone gives you the timezone offset in minutes.[/color]

          Dang, that means I'm twelve days in the past!
          [color=blue][color=green][color=darkred]
          >>> import time
          >>> time.timezone[/color][/color][/color]
          18000[color=blue][color=green][color=darkred]
          >>> 18000/60[/color][/color][/color]
          300
          (So that would be hours? ;-) )
          [color=blue][color=green][color=darkred]
          >>> 18000/60/24[/color][/color][/color]
          12

          Wait up guys!

          -Peter

          Comment

          • Mark Thalman

            #6
            Re: How to obtain GMT offset?

            According to <http://www.python.org/doc/2.4.1/lib/module-time.html>
            it is in seconds.

            --
            Mark


            On Aug 16, 2005, at 9:35 AM, Peter Hansen wrote:
            [color=blue]
            > Erik Max Francis wrote:
            >[color=green]
            >> time.timezone gives you the timezone offset in minutes.
            >>[/color]
            >
            > Dang, that means I'm twelve days in the past!
            >
            >[color=green][color=darkred]
            >>>> import time
            >>>> time.timezone
            >>>>[/color][/color]
            > 18000
            >[color=green][color=darkred]
            >>>> 18000/60
            >>>>[/color][/color]
            > 300
            > (So that would be hours? ;-) )
            >
            >[color=green][color=darkred]
            >>>> 18000/60/24
            >>>>[/color][/color]
            > 12
            >
            > Wait up guys!
            >
            > -Peter
            > --
            > http://mail.python.org/mailman/listinfo/python-list
            >
            >[/color]

            Comment

            • Bengt Richter

              #7
              Re: How to obtain GMT offset?

              On Mon, 15 Aug 2005 20:57:16 -0700, Erik Max Francis <max@alcyone.co m> wrote:
              [color=blue]
              >new pip wrote:
              >[color=green]
              >> I'm using Windows os. If the current system date time is '28 Jun 2001
              >> 14:17:15 +0700', how can I obtain the value '+0700' using python?[/color]
              >
              >time.timezon e gives you the timezone offset in minutes.
              >[/color]
              ITYM seconds?

              Regards,
              Bengt Richter

              Comment

              • Bengt Richter

                #8
                Re: How to obtain GMT offset?

                On Mon, 15 Aug 2005 20:57:16 -0700, Erik Max Francis <max@alcyone.co m> wrote:
                [color=blue]
                >new pip wrote:
                >[color=green]
                >> I'm using Windows os. If the current system date time is '28 Jun 2001
                >> 14:17:15 +0700', how can I obtain the value '+0700' using python?[/color]
                >
                >time.timezon e gives you the timezone offset in minutes.
                >[/color]
                Hm, ...

                From help(time):

                Variables:

                timezone -- difference in seconds between UTC and local standard time
                altzone -- difference in seconds between UTC and local DST time
                daylight -- whether local time should reflect DST
                tzname -- tuple of (standard time zone name, DST time zone name)

                I learned something: there is an altzone variable. But is that a constant,
                or is it zero during the standard-time part of the local year? (and since
                we do not have module-level properties, what happens if you start python
                during standard time and retrieve altzone after 1AM (or whenever the official
                switchover happens)? Lack of property would seem to make constants for both
                altzone and timezone safer. But then daylight should probably be an accessor
                function, if it can't be a property ;-)

                Regards,
                Bengt Richter

                Comment

                • Erik Max Francis

                  #9
                  Re: How to obtain GMT offset?

                  Bengt Richter wrote:
                  [color=blue][color=green]
                  > > time.timezone gives you the timezone offset in minutes.[/color]
                  >
                  > ITYM seconds?[/color]

                  I sure did. But at least minutes is a more entertaining answer.

                  --
                  Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/
                  San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
                  If you are afraid of loneliness, do not marry.
                  -- Anton Chekhov

                  Comment

                  Working...