Skip to content

Instantly share code, notes, and snippets.

@iqbalmalik89
Last active August 29, 2015 14:04
Show Gist options
  • Save iqbalmalik89/9b4050dae6de59c67c5b to your computer and use it in GitHub Desktop.
Save iqbalmalik89/9b4050dae6de59c67c5b to your computer and use it in GitHub Desktop.
Convert Time
<?php
function convertTime($date, $convert_from, $convert_to)
{
$current_time_zone = $date;
if(!empty($date))
{
if(!empty($convert_to))
{
$dt_obj = new \DateTime($date." ".$convert_from);
$dt_obj->setTimezone(new \DateTimeZone($convert_to));
$current_time_zone = date_format($dt_obj, 'Y-m-d H:i:s');
}
}
return $current_time_zone;
}
echo convertTime('2014-07-18 08:00:12', 'America/New_York', 'Asia/Karachi');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment