Pretty easy using strtotime
& date
:
$time = '2013-11-22T04:14:30';
$time_z = '2013-11-22T04:14:30Z';
$add_time = ' + 8 hours';
$unixtime = strtotime($time);
$unixtime_z = strtotime($time_z);
echo 'Unixtime: ' . date('Y-m-d h:i:s', $unixtime) . '<br />';
echo 'Unixtime Z: ' . date('Y-m-d h:i:s', $unixtime_z) . '<br />';
echo 'Unixtime (+ 8 hours): ' . date('Y-m-d h:i:s', $unixtime . $add_time) . '<br />';
echo 'Unixtime Z (+ 8 hours): ' . date('Y-m-d h:i:s', $unixtime_z . $add_time) . '<br />';
The output would be:
Unixtime: 2013-11-22 04:14:30
Unixtime Z: 2013-11-21 11:14:30
Unixtime (+ 8 hours): 2013-11-22 04:14:30
Unixtime Z (+ 8 hours): 2013-11-21 11:14:30
The key for this to work is the $add_time
which is just me adding + 8 hours
to the date string. But there are other methods to handle this based on your larger needs & input data.