PHP5 DateTime / DateTimeZone
Playing with the new DateTime / DateTimeZone objects in PHP5.2 for my ’secret project’; its great and simplifies working with timezones and the like.
I’ve created a quick script to show some basic usage of the DateTime / DateTimeZone code:
$adelaide_tz = new DateTimeZone('Australia/Adelaide');
$london_tz = new DateTimeZone('Europe/London');
$newyork_tz = new DateTimeZone('America/New_York');
$adelaide = new DateTime('now',$adelaide_tz);
$london = new DateTime('now',$london_tz);
$newyork = new DateTime('now',$newyork_tz);
print"Adelaide: " . $adelaide->format("F j, Y, g:i a") .
" Offset: " . $adelaide->getOffset();
print"London: " . $london->format("F j, Y, g:i a") .
" Offset: " . $london->getOffset();
print"New York: " . $newyork->format("F j, Y, g:i:a") .
" Offset: " . $newyork->getOffset();
Pretty simple, eh? ![]()