A black humor analysis _php technique for using mktime to get time stamps in PHP

Source: Internet
Author: User

The following code is the online most people give the time stamp reality, this one see can only say is to get the current date, but not a time stamp, do not have more explanation!

Copy Code code as follows:

$now = Mktime (0,0,0,date ("M"), Date ("D"), Date ("Y"));
echo "Now is". Date ("y/m/d", $now);

Show Results:
Now is 2012/05/30
Obviously this is not the result I want.
So, according to the old thinking, I take it for granted to the following form:
Copy Code code 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);

Notice the red part, usually if the month is M, then the minute should be M. Or the former with M, the latter with M.
Show Results:
Copy Code code as follows:

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

It seems that the assumption is not desirable, PHP syntax and other languages are still somewhat different.

No suspense, or just give us the right answer.
Copy Code code 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 ~ is "i" instead of what m or m, here is the example for everyone just want to let the beginner of PHP to take a few detours.
As for M. What does it mean, everyone will understand it by themselves ... Hey!!!
Show Results:
Copy Code code as follows:

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

There are too many people on the Internet to copy articles, not many people to delve into this, so as I like the PHP beginners at a loss. We copied before the copy is not more to do their own implementation in writing, to their own is an improvement, the reader has been responsible for the attitude.

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.