PHP application Mktime Get time Stamp example analysis

Source: Internet
Author: User
    1. $now = Mktime (0,0,0,date ("M"), Date ("D"), Date ("Y"));
    2. echo "Now is". Date ("y/m/d", $now);
Copy Code

Displaying results: Now was 2012/05/30 obviously this is not the result I want. Then, according to the old thinking, take for granted the following form of transformation:

    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);
Copy Code

Note the red part, usually if the month is in M, then the minute should be M. Or the former with M, the latter with M. displaying results: Warning:mktime () expects parameter 2 to being long, string given in D:\usr\webroot\testPHP\index.php on line 1970/01/01 08:jan:00

The correct answer is this:

    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);
Copy Code

haha ~ is "i" instead of what m or m, here is a sample of this example just want to let PHP beginners to take a few detours. As for what m means, smart, you must understand. Displaying results: Now was 2012/05/30 04:54:25

>>> you may be interested in the article: PHP in Time (), date (), mktime () The difference between time () and mktime () usage in PHP php strtotime () and Mktime () Issue of y2k38 Vulnerability 2038

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