Code Snippet
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | <?php date_default_timezone_set( "UTC" ); echo ( "<div style='font-family: consolas;'>" ); $cur_epochtime = time(); $cur_datetime = new DateTime( "@$cur_epochtime" ); $human_readible_utc = $cur_datetime ->format( "Y-m-d H:i:s" ); echo ( "[Current Time] " . $cur_datetime ->format( "U" ) . " " . $human_readible_utc . " UTC<br />" ); $cur_datetime ->setTimezone( new DateTimeZone( "Asia/Seoul" )); $human_readible_kst = $cur_datetime ->format( "Y-m-d H:i:s" ); echo ( "[Current Time] " . $cur_datetime ->format( "U" ) . " " . $human_readible_kst . " KST<br />" ); $new_datetime_utc_utc = new DateTime( $human_readible_utc ); echo ( "[String to Epochtime UTC-UTC] " . $new_datetime_utc_utc ->format( "U" ) . "<br />" ); $new_datetime_utc_kst = new DateTime( $human_readible_utc , new DateTimeZone( "Asia/Seoul" )); $interval = $new_datetime_utc_kst ->format( "U" ) - $new_datetime_utc_utc ->format( "U" ); echo ( "[String to Epochtime UTC-KST] " . $new_datetime_utc_kst ->format( "U" ) . " (" . $interval . ")<br />" ); $new_datetime_kst_kst = new DateTime( $human_readible_kst , new DateTimeZone( "Asia/Seoul" )); echo ( "[String to Epochtime KST-KST] " . $new_datetime_kst_kst ->format( "U" ) . "<br />" ); echo ( "<br />9 * 60 * 60 = " . (9 * 60 * 60) . "<br />" ); echo ( "</div>" ); ?> |
1 2 3 4 5 6 7 | [Current Time] 1522194136 2018-03-27 23:42:16 UTC [Current Time] 1522194136 2018-03-28 08:42:16 KST [String to Epochtime UTC-UTC] 1522194136 [String to Epochtime UTC-KST] 1522161736 (-32400) [String to Epochtime KST-KST] 1522194136 9 * 60 * 60 = 32400 |