Created
September 15, 2017 03:16
-
-
Save darkcolonist/eada042a15a5aefaec4dc7ef5673e0f3 to your computer and use it in GitHub Desktop.
timezone conversion php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$phTz = new DateTimeZone("Asia/Manila"); | |
$gmt0Time = new DateTimeZone("GMT0"); | |
$date = new DateTime(); | |
echo "default: "; | |
echo $date->format('r'); | |
echo "<br />"; | |
echo "manila: "; | |
echo $date->setTimezone($phTz)->format('r'); | |
echo "<br />"; | |
echo "UTC: "; | |
echo $date->setTimezone($gmt0Time)->format('r'); | |
echo "<br />"; | |
echo "------------------------------"; | |
echo "<br />"; | |
date_default_timezone_set("GMT0"); | |
$inbound_time = "2007-01-25 14:00:00"; | |
$inbound_time_obj = new DateTime($inbound_time); | |
$data = array( | |
array( | |
"message_id" => 9123, | |
"inbound_time" => $inbound_time_obj->format("r"), | |
"inbound_time_format" => $inbound_time_obj->format("Y-m-d H:i:s"), | |
"inbound_time_usertz" => $inbound_time_obj->setTimezone(new DateTimeZone("Asia/Manila"))->format("r"), | |
"inbound_time_usertz_format" => $inbound_time_obj->setTimezone(new DateTimeZone("Asia/Manila"))->format("Y-m-d H:i:s"), | |
"message" => "hi, how are you?", | |
"author_id" => 23, | |
"author_name" => "Christian", | |
"recipient_id" => 75, | |
"recipient_name" => "Jehtro", | |
) | |
); | |
echo json_encode($data); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment