How to get date and time from server

后端 未结 7 1899
感动是毒
感动是毒 2020-12-14 16:48

I want to retrieve date and time from server and according to it do some thing. For this I used following code:

$info = getdate();
$date = $info[\'mday\'];
$         


        
7条回答
  •  无人及你
    2020-12-14 17:16

    You should set the timezone to the one of the timezones you want.

    // set default timezone
    date_default_timezone_set('America/Chicago'); // CDT
    
    $info = getdate();
    $date = $info['mday'];
    $month = $info['mon'];
    $year = $info['year'];
    $hour = $info['hours'];
    $min = $info['minutes'];
    $sec = $info['seconds'];
    
    $current_date = "$date/$month/$year == $hour:$min:$sec";
    

    Or a much shorter version:

    // set default timezone
    date_default_timezone_set('America/Chicago'); // CDT
    
    $current_date = date('d/m/Y == H:i:s');
    

提交回复
热议问题