DateTime conversion function using PHP

It’s really very simple to convert times in different timezones using the following function.

function dateTimeConversion($datetime, $timezone="Europe/London") { $date = new DateTime($datetime, new DateTimeZone("UTC")); $date->setTimezone($timezone); return $date->format("Y-m-d H:i:s"); }
Code language: PHP (php)

As you can see, it takes 2 arguments, $datetime which is a time string and a $timezone which is a timezone to convert to.

A usage example would be:

echo dateTimeConversion("2012-05-01 17:09:58");
Code language: CSS (css)
Tags:
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments