How to get date and time from server

后端 未结 7 1881
感动是毒
感动是毒 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:14

    No need to use date_default_timezone_set for the whole script, just specify the timezone you want with a DateTime object:

    $now = new DateTime(null, new DateTimeZone('America/New_York'));
    $now->setTimezone(new DateTimeZone('Europe/London'));    // Another way
    echo $now->format("Y-m-d\TH:i:sO"); // something like "2015-02-11T06:16:47+0100" (ISO 8601)
    

提交回复
热议问题