How to convert mktime to milliseconds in PHP

Source: Internet
Author: User

The mktime () function is very useful for date calculation and validation. It automatically calculates the correct value for an input out of the range:

The code is as follows: Copy code

<? Php echo (date ("M-d-Y", mktime (,). "<br/> ");
Echo (date ("M-d-Y", mktime (,). "<br/> ");
Echo (date ("M-d-Y", mktime (,). "<br/> ");
Echo (date ("M-d-Y", mktime (,). "<br/>");?>

The output of the code above wocould be:
The above code will output the following results:

Jan-05-2002Feb-01-2002Jan-01-2001Jan-01-1999 don't need to explain more!

The code is as follows: Copy code

$ 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: Copy code

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

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

$ 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: Copy code

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

Okay,

Mktime () functionReturns the Unix timestamp of a date.

The parameter always represents the GMT date, soIs_dstThe result is not affected.

The parameters can be left empty from right to left. The blank parameters are set to the corresponding current GMT value.

Syntax

Mktime (hour, minute, second, month, day, year, is_dst)

Parameters Description
Hour Optional. The specified hour.
Minute Optional. Minutes.
Second Optional. Specified seconds.
Month Optional. Indicates the month in number.
Day Optional. Specified day.
Year Optional. Specified year. In some systems, the valid value ranges from 1901 to 2038. However, this restriction does not exist in PHP 5.
Is_dst

Optional. If the time is in the daylight saving time (DST) period, it is set to 1; otherwise, it is set to 0. If it is unknown, it is set to-1.

The is_dst parameter has been deprecated since 5.1.0. Therefore, the new time zone processing feature should be used.

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.