In PHP to convert a time-date to a timestamp (converted to milliseconds) we have a lot of methods, the simplest is to take advantage of the moment () directly to get the millisecond if it is like 2012-05-31, there are other methods to use.
The Mktime () function is useful for calculating dates and confirming date validity. It will automatically calculate the correct value for the input beyond the range:
| The code is as follows |
Copy Code |
|
");
Echo (Date ("M-d-y", Mktime (0,0,0,14,1,2001)). "
");
Echo (Date ("M-d-y", Mktime (0,0,0,1,1,2001)). "
");
Echo (Date ("M-d-y", Mktime (0,0,0,1,1,99)). "
");? > |
The output of the code above would be:
The code above will output the following result:
Jan-05-2002feb-01-2002jan-01-2001jan-01-1999 don't have 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); |
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:
| 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); |
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.
Show Results:
Warning:mktime () expects parameter 2 to being long, string given in d:usrwebroottestphpindex.php on line 46
Now is 1970/01/01 08:jan:00
It seems that it is not advisable to be judgmental, and PHP's syntax is somewhat different from other languages.
Not suspense, or directly to everyone the right 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 ~ 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, we can understand it by doing it by ourselves ... Hey!!!
Show Results:
| The code is as follows |
Copy Code |
|
Now was 2012/05/30 04:54:25 |
All right
The mktime () function returns a Unix timestamp for a date.
The parameter always represents the GMT date, so is_dst has no effect on the result.
Parameters can be left-to-right and empty, and empty parameters will be set to the corresponding current GMT value.
Grammar
Mktime (HOUR,MINUTE,SECOND,MONTH,DAY,YEAR,IS_DST)
| Parameters |
Description |
| Hour |
Optional. Specified hours. |
| Minute |
Optional. Specify minutes. |
| Second |
Optional. Specify seconds. |
| Month |
Optional. Specifies the number of months to be represented. |
| Day |
Optional. Prescribed days. |
| Year |
Optional. Prescribed year. On some systems, the legal value is between 1901-2038. However, there is no such limit in PHP 5. |
| Is_dst |
Optional. If the time is in daylight saving time (DST), set to 1, otherwise set to 0 and if unknown, set to-1.
Since 5.1.0, the IS_DST parameter has been discarded. Therefore, you should use the new Time zone processing feature. |
http://www.bkjia.com/PHPjc/629128.html www.bkjia.com true http://www.bkjia.com/PHPjc/629128.html techarticle in PHP to convert the time-date into a timestamp (converted to milliseconds) we have a lot of methods, the simplest is to take advantage of the moment () directly to get the millisecond if it is like 2012-05-31, there is to use ...