In PHP, mktime is converted to milliseconds. In php, there are many ways to convert a time date into a timestamp (converted to milliseconds). The simplest way is to use time () we can directly obtain millisecond. if it is like, there are many ways to convert the time and date to the timestamp (converted to milliseconds) in php, the simplest way is to use time () to directly obtain the millisecond. if it is like, you need to use other methods.
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: |
|
"); Echo (date ("M-d-Y", mktime ))." "); Echo (date ("M-d-Y", mktime ))." "); Echo (date ("M-d-Y", mktime ))." ");?> |
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: |
|
$ 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:
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: |
|
$ 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 |
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. |
There are many ways to convert latency (to milliseconds). The simplest way is to use time () to directly obtain the millisecond. if it is like, use it...