- var_dump: documentation ( source)
- is_numeric: documentation ( source)
- date: documentation ( source)
- strtotime: documentation ( source)
- gmdate: documentation ( source)
<?php
function time_offset($timezone = null)
{
if ($timezone <> null) {
$offset = false;
try {
$time = @new DateTime();
@$time->setTimezone(new DateTimeZone($timezone));
$offset = @$time->getOffset();
} catch (Exception $e) {
}
$output = is_numeric($offset) ? $offset : false;
} else {
$output = strtotime(date("Y-m-d H:i:s")) - strtotime(gmdate("Y-m-d H:i:s"));
}
return $output;
}
var_dump(time_offset("Asia/Calcutta"));