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 $utc_time variable return date format in UTC

Comments

No comments yet. Why don’t you start the discussion?

    Leave a Reply