Ajouve
Ajouve

Reputation: 10049

Timezone php Symfony2

I'm using Symfony2 and I'd like to fetch my dates in function to the user timezone. So my dates are stored in a database in the server timezone.

I'd like to convert this date to the user timezone before fetching and set the date to the server timezone before saving it into my database.

I'm using Datetime

Thanks or your help

Upvotes: 0

Views: 224

Answers (1)

Pierre
Pierre

Reputation: 782

Try somethink like this :

$userTimezone = new DateTimeZone('America/New_York');
$serverDateTime = new DateTime('2013-08-05 10:10');
$offset = $userTimezone->getOffset($serverDateTime);
echo $offset;

Now with the offset you should be able to modify the date like this :

$serverDateTime->modify('+'.$offset.' seconds');

Upvotes: 1

Related Questions