Phpstrtotime () function Time and Date conversion. In php, the strtotime () function resolves the date and time descriptions of any English text into Unix timestamps. This function is also frequently used. if you need it, please refer to it. Syntax in php, the strtotime () function resolves the date and time descriptions of any English text into Unix timestamps. This function is also frequently used. For more information, see.
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: |
|
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: |
|
$ 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 .) $ Date = "06/10/2011"; // 6 October 2011 pm $ OtherDate = ""; // 6 October 2011 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 ?> |
The Parse () function parses the datetime description of any English text into a Unix timestamp. This function is also frequently used. For more information, see. Syntax...