{"id":1893,"date":"2018-10-26T19:46:20","date_gmt":"2018-10-26T19:46:20","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=1893"},"modified":"2022-02-17T07:14:01","modified_gmt":"2022-02-17T07:14:01","slug":"time-zones","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/php\/date-and-time\/time-zones","title":{"rendered":"Time Zones"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Get DateTime\u00a0now for a specific time zone<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">Example 1<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>  \/\/Get time now in specified time zone\n  $dt = new DateTime(\"now\", new DateTimeZone('Europe\/London'));   \/\/E.g. 'UTC', 'Europe\/London', full list at: https:\/\/en.wikipedia.org\/wiki\/List_of_tz_database_time_zones\n\n  $TimeNow = $dt->format('Y-m-d H:i:s');<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Example 2<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>\n\ttry\n\t{\n\t\t$TimeZone = new DateTimeZone('America\/New_York');\n\t\t$LocalDateTime = new DateTime(gmdate(\"Y-m-d\\TH:i:s\"));\t\t\t\t\t\/\/gmdate gives UTC\/GMT datetime\n\t\t$LocalDateTime->setTimezone($TimeZone);\n\t\techo $LocalDateTime->format('Y-m-d\\TH:i:s');\n\n\t}\n\tcatch (Exception $e)\n\t{\n\t\t\/\/Will occur if DateTimeZone string is not valid\n\t}\n\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Get DateTime\u00a0now for a specific time zone Example 1 Example 2<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[],"class_list":["post-1893","post","type-post","status-publish","format-standard","hentry","category-date-and-time"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/1893","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/comments?post=1893"}],"version-history":[{"count":3,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/1893\/revisions"}],"predecessor-version":[{"id":2914,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/1893\/revisions\/2914"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=1893"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=1893"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=1893"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}