I think I'm going nuts as this has to be simple.
The time on my computer is currently: 14:41 When I run any of the code below, it returns: 13:41.
$date = new DateTime();
$date->format('Y-m-d H:i:s') //13:41
date('Y-m-d H:i:s') //13:41
date_default_timezone_get()
returns UTC.
Now I understand why it's an hour behind (because we are in daylight saving time) BUT isn't there a function that takes all this into account and returns the actual time?
p.s I am expecting to have missed something obvious here.
Edit: date('Y-m-d H:i:s -- I -- e');
returns 2013-09-13 14:15:47 -- 0 -- UTC
. Shouldn't the I
param be return 1?
Don't rely on php.ini settings. If you want control over the timezone, control the timezone:
<?php
$date = new DateTime();
$date->setTimezone(new DateTimeZone('Europe/London'));
$date->format('Y-m-d H:i:s e')
Replace "Europe/London" with whatever your definition of "actual time" is.
As an aside: if date_default_timezone_get()
returns UTC, then the output of $date->format()
is the same on every machine with a correct clock. That's the point of UTC.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다