A black humor in PHP that uses mktime to get the timestamp

Source: Internet
Author: User
Mktime (hour, minute, second, month, day, year, is_dst) is the syntax of mktime. It is not difficult to write a timestamp code at a glance! The following code is a timestamp provided by most people on the Internet. At first glance, it can only be said that the current date is obtained, rather than the timestamp. Do not explain it more! 1 $ nowmktime

Mktime (hour, minute, second, month, day, year, is_dst) is the syntax of mktime. It is not difficult to write a timestamp code at a glance! The following code is a timestamp provided by most people on the Internet. At first glance, it can only be said that the current date is obtained, rather than the timestamp. Do not explain it more! 1 $ now = mktime

Mktime (hour, minute, second, month, day, year, is_dst) is the syntax of mktime. It is not difficult to write a timestamp code at a glance!

The following code is a timestamp provided by most people on the Internet. At first glance, it can only be said that the current date is obtained, rather than the timestamp. Do not explain it more!

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

Display result:

Now is 2012/05/30

Obviously, this is not the result I want.

As a result, according to the old thinking, I take it for granted to the following form:

1 $now = mktime(date("h"),date("M"),date("s"),date("m"),date("d"),date("Y"));2 echo "now is ".date("Y/M/d h:i:s", $now);

Pay attention to the red part. Generally, if the month is m, the minute should be M. Or the former uses M, and the latter uses m.

Display result:

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

It seems that subjective assumptions are not advisable. The PHP syntax is different from other languages.

Don't sell off the customs, or directly give you the correct answer

1 $now = mktime(date("h"),date("i"),date("s"),date("m"),date("d"),date("Y"));2 echo "now is ".date("Y/m/d h:i:s", $now);

Haha ~ It is "I" rather than m or M. Here we will give you an example to avoid detours for PHP beginners.

As for what M means, you can understand it after you do it yourself... hey !!!

Display result:

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

There are too many people who copy articles on the Internet. Not many people go into this, making PHP beginners like me at a loss. Before copying and copying data, do you want to write more manually? This is an improvement for yourself and a always-responsible attitude for readers.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.