timezones...

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

    #1

    timezones...

    I'm going slowly mad here... What I want to do is to be able to convert
    from a timezone name eg "Europe/London" to an offset from UTC ... in
    this case it's +1 hour at the moment. The end result is to convert an
    utc timestamp held in a mysql database into a display field in the
    relevant local time ( not doing so can be most tedious when you live in
    GMT+12! ).

    There must be a simple way... I've got linux and mysql available if
    either of these help.

    Cheers,


    Steve
  • Jasper Bryant-Greene

    #2
    Re: timezones...

    Steve wrote:[color=blue]
    > I'm going slowly mad here... What I want to do is to be able to convert
    > from a timezone name eg "Europe/London" to an offset from UTC ... in
    > this case it's +1 hour at the moment. The end result is to convert an
    > utc timestamp held in a mysql database into a display field in the
    > relevant local time ( not doing so can be most tedious when you live in
    > GMT+12! ).[/color]

    Just a stab in the dark as I don't have a Linux box handy to test this
    on, but shouldn't the files in (from memory) /usr/share/zoneinfo have
    offsets in them?

    They are named by timezone name and could just be accessed via
    file_get_conten ts.

    --
    Jasper Bryant-Greene
    Cabbage Promotions

    Comment

    • Steve

      #3
      Re: timezones...

      Jasper Bryant-Greene wrote:[color=blue]
      > Steve wrote:
      >[color=green]
      >> I'm going slowly mad here... What I want to do is to be able to
      >> convert from a timezone name eg "Europe/London" to an offset from UTC
      >> ... in this case it's +1 hour at the moment. The end result is to
      >> convert an utc timestamp held in a mysql database into a display field
      >> in the relevant local time ( not doing so can be most tedious when you
      >> live in GMT+12! ).[/color]
      >
      >
      > Just a stab in the dark as I don't have a Linux box handy to test this
      > on, but shouldn't the files in (from memory) /usr/share/zoneinfo have
      > offsets in them?
      >
      > They are named by timezone name and could just be accessed via
      > file_get_conten ts.
      >[/color]
      not that simple...

      /usr/share/zoneinfo/Europe/London is a binary file. zdump will give me
      the current time there. but i still need to calculate the offset from utc!

      Steve

      Comment

      • Jasper Bryant-Greene

        #4
        Re: timezones...

        Steve wrote:[color=blue]
        > not that simple...
        >
        > /usr/share/zoneinfo/Europe/London is a binary file. zdump will give me
        > the current time there. but i still need to calculate the offset from utc!
        >
        > Steve[/color]

        Subtract UTC from current time there and you will have the offset.

        --
        Jasper Bryant-Greene
        Cabbage Promotions

        Comment

        • Brion Vibber

          #5
          Re: timezones...

          Steve wrote:[color=blue]
          > I'm going slowly mad here... What I want to do is to be able to convert
          > from a timezone name eg "Europe/London" to an offset from UTC ... in
          > this case it's +1 hour at the moment. The end result is to convert an
          > utc timestamp held in a mysql database into a display field in the
          > relevant local time ( not doing so can be most tedious when you live in
          > GMT+12! ).[/color]

          PHP's date() function can give you the timezone offset in seconds. You
          can set the current timezone by setting the TZ environment variable
          (putenv() and getenv()).

          -- brion vibber (brion @ pobox.com)

          Comment

          • Steve

            #6
            Re: timezones...

            Brion Vibber wrote:[color=blue]
            > Steve wrote:
            >[color=green]
            >> I'm going slowly mad here... What I want to do is to be able to
            >> convert from a timezone name eg "Europe/London" to an offset from UTC
            >> ... in this case it's +1 hour at the moment. The end result is to
            >> convert an utc timestamp held in a mysql database into a display field
            >> in the relevant local time ( not doing so can be most tedious when you
            >> live in GMT+12! ).[/color]
            >
            >
            > PHP's date() function can give you the timezone offset in seconds. You
            > can set the current timezone by setting the TZ environment variable
            > (putenv() and getenv()).
            >
            > -- brion vibber (brion @ pobox.com)[/color]
            Brion... perfect!

            The few grey hairs I have left thank you too!

            Cheers,

            Steve

            Comment

            • Steve

              #7
              Re: timezones...

              Brion Vibber wrote:[color=blue]
              > Steve wrote:
              >[color=green]
              >> I'm going slowly mad here... What I want to do is to be able to
              >> convert from a timezone name eg "Europe/London" to an offset from UTC
              >> ... in this case it's +1 hour at the moment. The end result is to
              >> convert an utc timestamp held in a mysql database into a display field
              >> in the relevant local time ( not doing so can be most tedious when you
              >> live in GMT+12! ).[/color]
              >
              >
              > PHP's date() function can give you the timezone offset in seconds. You
              > can set the current timezone by setting the TZ environment variable
              > (putenv() and getenv()).
              >
              > -- brion vibber (brion @ pobox.com)[/color]

              ....it's so simple, here's my solution.

              <?
              function GetOffset ( $TimeZone )
              {


              //Save the current setting
              $SaveZone = getenv ( "TZ" );
              putenv ( "TZ=$TimeZo ne" );
              $Offset = date ( "Z" );
              putenv ( "TZ=$SaveZo ne" );


              echo "$TimeZone is $Offset seconds from UTC\n";
              return $Offset;
              }
              GetOffset ( "Pacific/Auckland" );
              GetOffset ( "Europe/London" );
              ?>

              Comment

              Working...