On 5/04/2011, at 3:35 AM, Ian wrote: > Hi, > > I have a problem using the php built in classes DateTime and DateTimeZone. > > The idea behind the following code is to return the timestamp for the > current time in Singapore (or other places). What it actually returns > is the timestamp for the local system. Other formatted dates appear to > return correctly, which is why I am puzzled. > > I am using the latest php 5.3.6 compiled from source on a OpenVZ CentOS > container. All packages are up to date. > > Am I doing something wrong or is this a bug? > > I can workaround this problem my parsing the correctly formatted date > using strtotime() but I would like to know what's going on. > > > > This is the output of the script: > > Current time in Asia/Singapore is 2011-04-04 23:32:36 > Timestamp for Asia/Singapore is 1301931156 > Date created from previous timestamp is 2011-04-04 16:32:36 > > The code is : > > <?php > > $timezone="Asia/Singapore"; > > # Create Timezone object > $remote_timezone = new DateTimeZone($timezone); > > # Create datetime object > $remote_time = new DateTime("now" , $remote_timezone); > > # Print the date > print "Current time in {$timezone} "; > print "is {$remote_time->format("Y-m-d H:i:s")}<br/>"; > > # Print the timestamp > print "Timestamp for {$timezone} "; > print "is {$remote_time->format("U")}<br />"; > > # Get the timestamp and create a date from it > $timestamp = (int)$remote_time->format("U"); > > # Show the formatted date created from timestamp > print "Date created from previous timestamp is "; > print date("Y-m-d H:i:s",$timestamp)."<br/>"; > > ?> May I suggest including the timezone in your date format (O or e)? It may show the two date strings to be equivalent. --- Simon Welsh Admin of http://simon.geek.nz/ Who said Microsoft never created a bug-free program? The blue screen never, ever crashes! http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php