mysql - how to convert time php so that it converts PT to CT -
i trying convert time default site time pt new york, want convert once pulling database heres code
date_default_timezone_set('america/los_angeles') ; $site_time = date("h:i:s",time()) ; this inserts time in pt
$insert_chat = mysqli_query($conn, "insert chat (time) values '$site_time'" ); $select = mysqli_query($conn, "select time chat") ; while ($row = mysqli_fetch_array($select)){ $chat_time = $row['time'] ; after pull pt time database convert new york ct
date_default_timezone_set('america/new_york') ; $user_time = date("h:i a",strtotime($chat_time)) ; echo $user_time ; but when echo time still showing pt , doing wrong
a working solution using php standard objects:
$dt = new datetime( '2017-01-01 09:00:00', new datetimezone('america/los_angeles') ); $dt->settimezone(new datetimezone('america/new_york')); echo $dt->format("h:i a"); // 12:00 pm what happens in code $chat_time has no timezone associated it; it's string. calling date_default_timezone_set has no bearing on it. when call date formats string.
Comments
Post a Comment