Today is 24 gen 2012 for Europe. I’m using mktime to get a DateTime object about today, midnight time. Why it says 23 o’clock of 23 gen, instead of 00:00 of 24 gen?
var_dump(new DateTime('@' . mktime(0, 0, 0)));
Output:
object(DateTime)[5]
public 'date' => string '2012-01-23 23:00:00' (length=19)
public 'timezone_type' => int 1
public 'timezone' => string '+00:00' (length=6)
mktime uses the local time zone information when deciding what the returned time should be and returns a value that is aligned to UTC. If you want to override this, then you need to pass in an explicit
is_dst = 0parameterYou then use this UTC time when constructing the DateTime object (this is what the
@does), which means that the hour offset is replicated into the DateTime object.Because
mktimeuses the local timezone information, you should use the alternativegmmktimeif you want to obtain midnight UTC using –If you want midnight server time, and then to convert the output to a user’s timezone e.g. ‘Europe/Paris’ you would do the following:
You can convert it to your server’s local time using: