The Strtotime () function in PHP parses the datetime description of any English text into a Unix timestamp, a function that we often use, and a friend to refer to.
Grammar
Strtotime (time,now) parameter description
TIME specifies a string of times to parse.
Now is used to calculate the timestamp of the return value. If this argument is omitted, the current time is used.
Example
| The code is as follows |
Copy Code |
Echo Strtotime ("Now"), "n"; Echo Strtotime ("Ten September"), "n"; Echo strtotime ("+1 Day"), "n"; Echo strtotime ("+1 Week"), "n"; Echo strtotime ("+1 Week 2 days 4 hours 2 Seconds"), "n"; Echo Strtotime ("next Thursday"), "n"; Echo Strtotime ("Last Monday"), "n"; ?> |
Example #2 Failure Check
| The code is as follows |
Copy Code |
| !--? php $str = ' not good '; //Previous to PHP 5.1.0 you would compare with-1, instead of false if (($timestamp = Strtotime ($str)) = = = = False) { echo "The string ($STR) is bogus"; } else { echo "$str = =". Date (' L DS of F Y h:i:s A ', $timestamp); } ? I just found out PHP thinks slashes in date-formats aren ' t very European: (I Guess this is not a B UG, just the IT works. But correct me if I ' m wrong.) !--? php $date = "06/10/2011 14:28";//6 October 2:28 pm $otherDate = "06-10-2011 14:28";//6 Octo ber 2:28 PM Echo $stamp = Strtotime ($date). " "; Outputs 1307708880 Echo $otherStamp = Strtotime ($otherDate). " "; Outputs 1317904080 Echo Date ("D-m", $stamp);//Outputs 10-06 Echo date ("D-m", $otherStamp);//outputs 06 -10 ; |
http://www.bkjia.com/PHPjc/445317.html www.bkjia.com true http://www.bkjia.com/PHPjc/445317.html techarticle The strtotime () function in PHP parses the datetime description of any English text into a Unix timestamp, a function that we often use, and a friend to refer to. Grammar ...