How to convert local timestamp to UTC

UTC timestamp is useful when user want to see his local time based on server time. So we can convert any timestamp to UTC or UTC time to local timestamp.

Convert current timestamp to UTC

$date_object = new DateTime('now', new DateTimeZone("Asia/Kolkata"));
$date_object->setTimezone(new DateTimeZone('UTC'));
$utc_time = $date_object->format('Y-m-d H:i:s');

above example <strong>$utc_time</strong> variable return date format in UTC

Leave a Reply