strtotime ("today") returns the wrong time?

I am trying to create a selection list starting from the current date of the user. I want it set to midnight in unix timestamp format.

That is all I do:

$today = strtotime('today'); echo $today; 

This is my result:

 1333144800 

namely: Fri, March 30, 2012 22:00:00 GMT in accordance with the eras converter (incorrect for a couple of hours.)

+10
source share
5 answers

If you want strtotime () to return a timestamp relative to UTC (00:00:00 UTC instead of, for example, 00:00:00 UTC + 2, if your system is set to a time zone with an offset of 2 hours against UTC / GMT) , you need to indicate that:

 $today = strtotime('today UTC'); 
+21
source

GMT (+0) time

 echo $today = strtotime('today GMT'); echo "<br>" . $today = date("dmY H:i:s", $today); 

We expect your server to work in GMT - this is the best (for maneuvering with time display later). If not, you MUST adjust php.ini, set this to "date.timezone = GMT".

When you do this, you will see 00:00 with my codes.

Then you must create a function (i.e. DisplayDate ()) in the script to correctly display your site dates if

  • You are not in GMT
  • or /, and if you want your users to see the time in their time zone with a choice of time zone, for example.

DisplayDate () should also include support for daylight changes (0 or +1 hour / summer and winter time).

+6
source
 strtotime( $time ) 

It is intended to return timetamp unix, that is, it will return the number of seconds from January 1, 1970. http://www.php.net/manual/en/function.strtotime.php

To get around this, use something like:

 $today = date("d/m/YH:i:s", strtotime('today')); echo $today; 
+2
source

You may need a certain time, as well as a day:

 $today_midnight = strtotime('today UTC 00:00'); 
+1
source

You should check the time zone configuration in the php.ini file. In my case (I live in El Salvador) I had to change it as follows:

 date.timezone = America/El_Salvador 
0
source

All Articles