DateTime using DateTimeZone Timestamp problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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/>";

?>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux