0

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

2
  • If you haven't saved the user timezone somewhere, this isn't possible. Php runs on the server and does not know anything about the user Commented Aug 5, 2013 at 7:14
  • This is not a problem I can have the user timezone using ajax ajax and session, the answer is how to convert datetimes in function of timezone not repeating myself each time I want to save or fetch a date Commented Aug 5, 2013 at 7:18

1 Answer 1

1

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');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.