A gallows humor analysis in PHP that USES mktime to get a timestamp

  • 2020-05-16 06:36:58
  • OfStack

The following code is a timestamp given by most people on the Internet. It can only be used to get the current date, but not a timestamp.

 
$now = mktime(0,0,0,date("m"),date("d"),date("Y")); 
echo "now is ".date("Y/m/d", $now); 

Display results:
now is 2012/05/30
Obviously that's not what I wanted.
So, in the old way of thinking, I took it for granted that I would change it into the following form:
 
$now = mktime(date("h"),date("M"),date("s"),date("m"),date("d"),date("Y")); 
echo "now is ".date("Y/M/d h:i:s", $now); 

Notice the red part, usually if the month is m, then the minutes should be M. Or M for the former and m for the latter.
Display results:
 
Warning: mktime() expects parameter 2 to be long, string given in D:\usr\webroot\testPHP\index.php on line 46 
now is 1970/01/01 08:Jan:00 

It seems that subjective assumption is not desirable. The grammar of PHP is somewhat different from other languages.

I'm not going to keep you in suspense, but I'm going to give you the right answer
 
$now = mktime(date("h"),date("i"),date("s"),date("m"),date("d"),date("Y")); 
echo "now is ".date("Y/m/d h:i:s", $now); 

It's "i", not "m" or "M". The example given here is just to make it easier for beginners to learn PHP.
As for what M means, you can do 1 by yourself. Hey hey!!
Display results:
 
now is 2012/05/30 04:54:25 

There are so many people copying articles from each other on the Internet that not many people go deep into this, leaving beginners like me at a loss what to do with PHP. Copy copy before you move your hands to achieve 1 in writing, is an improvement on yourself, is also a direct and responsible attitude to the reader.


Related articles: