I’m currently adding support for internationalisation to a system written in PHP. All dates are now stored as UTC, and displayed according to individual user localisation preferences.
However when a user inputs a date time (such as to specify a certain time window), the date time they input gets interpreted as a UTC datetime, not their local datetime. For the internationalisation to be complete the system needs to assume that a datetime entered by the user refers to their local time.
How do I convert a date string (ie ‘YYYY-MM-DD HH:MM’) into a unix timestamp for the correct localisation?
- Further Clarification –
All dates in database = UTC Timestamps
All HTML Pages display users local time (as defined in their settings)
HTML form has date that defaults to current local time
PHP must treat that date time as local not UTC
PHP must convert this local date timestring into UTC timestamp
Assuming you know the timezone of the user, which he presumably chose in the preferences somewhere:
This requires a recent version of PHP with
DateTime.