How can i convert a date like this: 2012-07-16 01:00:00 +00
(it's in the UTC +00:00
timezone) to UTC +04:00
timezone? Ensuring that daylight saving will be handelled correctly?
相关问题
- 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
To help with the solution, you need to get the last part of the string (the offset part) and look it up against a simple lookup. you can use a regex or
substr()
(maybe) to get the offest part. Then, when you have a + or - value, use a maximum of 24 lookups against possible timezones which you can use with PHP's possible timezones - if the offset is the same, who cares what the actual country/location is?The use date_default_timezone_set to apply the right one.
You can also use GMT time also and convert it to your requirement afterwards
GMT refers Greenwich Mean Time which is common all over the world.
Use
DateTime
andDateTimeZone
.