Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Linux, Apache, MySQL, PHP
  4. Time Zone Conversion PHP [modified]

Time Zone Conversion PHP [modified]

Scheduled Pinned Locked Moved Linux, Apache, MySQL, PHP
phphelptutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DinoRondelly
    wrote on last edited by
    #1

    I am having a problem understand how to work with time zones in PHP I am trying to create a function where i can pass it a time zone and it will calculate the time in that time zone. i have read countless forms about this and still have hit a brick wall. If any one has any links or information they can share on how to do this i would be forever grateful. All i need to do is find out what the current time is in eastern pacific and central time zones.

    P S 2 Replies Last reply
    0
    • D DinoRondelly

      I am having a problem understand how to work with time zones in PHP I am trying to create a function where i can pass it a time zone and it will calculate the time in that time zone. i have read countless forms about this and still have hit a brick wall. If any one has any links or information they can share on how to do this i would be forever grateful. All i need to do is find out what the current time is in eastern pacific and central time zones.

      P Offline
      P Offline
      Peter_in_2780
      wrote on last edited by
      #2

      This is a cut'n'paste from the DateTime::setTimezone section of the PHP manual:

      Example #1 Setting and getting DateTimeZone objects

      <?php
      date_default_timezone_set('Europe/London');

      $datetime = new DateTime('2008-08-03 12:35:23');
      echo $datetime->getTimezone()->getName() . "\n";

      $datetime = new DateTime('2008-08-03 12:35:23');
      $la_time = new DateTimeZone('America/Los_Angeles');
      $datetime->setTimezone($la_time);
      echo $datetime->getTimezone()->getName();
      ?>
      The above example will output:

      Europe/London
      America/Los_Angeles

      Elsewhere in the date/time chapter there are heaps of examples of various date/time manipulations. What I think you want to do is something like this:

      $datetime = new DateTime(something);
      $datetime->setTimezone(xxx);
      $timexxx = $datetime->format($formatstring);
      $datetime->setTimezone(yyy);
      $timeyyy = $datetime->format($formatstring);

      [edit]fixed html quoting[/edit]

      Software rusts. Simon Stephenson, ca 1994.

      modified on Thursday, August 5, 2010 8:47 PM

      1 Reply Last reply
      0
      • D DinoRondelly

        I am having a problem understand how to work with time zones in PHP I am trying to create a function where i can pass it a time zone and it will calculate the time in that time zone. i have read countless forms about this and still have hit a brick wall. If any one has any links or information they can share on how to do this i would be forever grateful. All i need to do is find out what the current time is in eastern pacific and central time zones.

        S Offline
        S Offline
        sonam_123
        wrote on last edited by
        #3

        you can use GMT time function for this u need to just pass gmt and it will return correct time. plz explain more if ur problem is not solve with this

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups