Can anyone suggest an easy method to convert date and time to different timezones in php?
Can anyone suggest an easy method to convert date and time to different timezones
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use the datetime object or their function aliases for this:
Example (abridged from PHP Manual)
Edit regarding comments
That’s not a problem. When a user logs in, you determine his timezone and set it to your DateTime object just like shown. I’m using a similar approach in one of my projects and it works like a charm.
You store the time either as a timestamp or a datetime in one timezone. When you query a DateTime field, you either convert the time in a DateTime object to this timezone or – if your db supports it – query with the selected timezone.