Display a stored datetime as the user localtime

Hi guys

I have a value in my database, lets says

2011-01-07 09:00:00

How can I make this show as the users local time, so if there timezone is 5 hours in front then it would be

2011-01-07 14:00:00

Regards

Chris

Hi Chris.


<?php
$here = new DateTime('2011-01-07 09:00:00', new DateTimeZone('Europe/London'));
echo $here->format("r\
");

$there = clone $here;
$there->setTimezone(new DateTimeZone('America/New_York'));
echo $there->format("r\
");

/*
  Fri, 07 Jan 2011 09:00:00 +0000
  Fri, 07 Jan 2011 04:00:00 -0500
*/

That is fanastic in wamp but when I upload I get this error

Fatal error: Cannot instantiate non-existent class: datetime in /home/joiyoya/public_html/test.php on line 5

PHP 4 again huh? It would save a lot of trouble if you just updated it. :stuck_out_tongue:

OK, let me get back to you with a PHP 4 solution once I’ve grabbed a coffee and put my math head on.

:slight_smile:

Thank you Anthony. Ive upgraded.

As far as I remember I had worked on it with [fphp]putenv[/fphp] function. Try like this once.


putenv ('TZ=Europe/London');
echo date('Y-m-d H:i:s');