Syntax
Strtotime (time, now) parameter description
Time specifies the time string to be parsed.
Now is used to calculate the timestamp of the returned value. If this parameter is omitted, the current time is used.
Example
The code is as follows: |
Copy code |
<? Php Echo (strtotime ("now ")); Echo (strtotime ("3 October 2005 ")); Echo (strtotime ("+ 5 hours ")); Echo (strtotime ("+ 1 week ")); Echo (strtotime ("+ 1 week 3 days 7 hours 5 seconds ")); Echo (strtotime ("next Monday ")); Echo (strtotime ("last Sunday ")); ?> Output: 1138614504 1128290400 1138632504 1139219304 1139503709 1139180400 1138489200 |
Example #1 strtotime () Example
The code is as follows: |
Copy code |
<? Php Echo strtotime ("now"), "n "; Echo strtotime ("10 September 2000"), "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 wowould 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 bug, just the way it works. But correct me if I'm wrong .) <? Php $ Date = "06/10/2011"; // 6 October 2011 pm $ OtherDate = ""; // 6 October 2011 pm Echo $ stamp = strtotime ($ date). "<br/>"; // outputs 1307708880 Echo $ otherStamp = strtotime ($ otherDate). "<br/>"; // outputs 1317904080 Echo date ("d-m", $ stamp); // outputs 10-06 Echo date ("d-m", $ otherStamp); // outputs 06-10 ?> |