How do I convert a date/time string (e.g. 2011-01-01 15:00:00) that is UTC to any given timezone php supports, such as America/New_York, or Europe/San_Marino.
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
PHP's
DateTime
object is pretty flexible.General purpose normalisation function to format any timestamp from any timezone to other. Very useful for storing datetimestamps of users from different timezones in a relational database. For database comparisons store timestamp as UTC and use with
gmdate('Y-m-d H:i:s')
Usage:
PHP's
DateTime
object is pretty flexible.Since the user asked for more than one timezone option, then you can make it generic.
Generic Function
Usage:
Output:
2011-04-21 09:14:00
How about:
Assuming the UTC is not included in the string then:
Or you could use the DateTime object.