A black humor analysis of using mktime to obtain timestamps in PHP_PHP Tutorial

WBOY
Release: 2016-07-21 15:18:47
Original
876 people have browsed it

The following code is the timestamp reality given by most people on the Internet. You can tell at a glance that this can only be said to obtain the current date, not a timestamp. No need to explain it further!

Copy code The code is as follows:

$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 this is not the result I want.
So, according to the old thinking, I naturally transformed it into the following form:
Copy the code The code is as follows:

$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);

Pay attention to the red part. Usually if the month is m, then the minute is It should be M. Or use M for the former and m for the latter.
Display results:
Copy code The code is as follows:

Warning: mktime() expects parameter 2 to be long, string given in D:usrwebroottestPHPindex.php on line 46
now is 1970/01/01 08:Jan:00

It seems that subjective judgment is not advisable, PHP syntax and other There are some differences in language.

Without further ado, let me give you the correct answer directly
Copy the code The code is as follows:

$ 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);

Haha~ It's "i" instead of m or M. Here are some examples This example is just to avoid some detours for beginners of PHP.
As for what M means, you will understand after you try it yourself... Hehe! ! !
Display results:
Copy code The code is as follows:

now is 2012/05/30 04:54:25

There are too many people copying each other’s articles on the Internet, and not many people go into this, leaving PHP beginners like me at a loss. Before copying and copying, should you be more hands-on and implement it yourself before writing it? It will improve yourself and always be responsible for the readers.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/325425.htmlTechArticleThe following code is the timestamp reality given by most people on the Internet. This can only be said at a glance It is to obtain the current date, not a timestamp. No need to explain more! Copy code...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template