A black humorous analysis of timestamp obtained using mktime in PHP

Source: Internet
Author: User
Mktime (hour, minute, second, month, day, year, is_dst) is the syntax of mktime, at a glance, it is not difficult to write a timestamp code. the following code is a real timestamp provided by most people on the internet. at first glance, it can only be said that the current date is obtained, not the timestamp, no need to explain more!

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 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:

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. generally, if the month is m, the minute should be M. Or the former uses M, and the latter uses m.
Display result:

The code is as follows:


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 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

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 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:

The code is as follows:


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.