This article mainly introduces the usage of strtotime function in PHP, analyzes the parameter meaning and corresponding usage of strtotime function in detail, and applies to the situation of time format transformation, the friend who needs can refer to
This example describes the use of Strtotime functions in PHP. Share to everyone for your reference. Specific as follows:
Strtotime (String $ time [, int $ now]) int strtotime (string $time [, int $now] This function expects to get a date format containing US English and will attempt to parse it into a Unix timestamp ( How many seconds since January 1, 1970 00:00:00 Monday that format), relative to the time stamp provided now, or the current time if not provided now
This function uses the TZ environment variable (if any) to calculate the timestamp, and since PHP 5.1.0 has an easier way to determine the time zone of all/datetime functions used, this process is explained on a page of the Date_default_timezone_get () function.
Parsing the string, in PHP 5.0.0, is not allowed in microseconds, since PHP 5.0.0 they are allowed, but ignored.
Now which is the time stamp used as the calculated cardinality relative to the date.
Return value: Returns a timestamp in the successful return, otherwise false, before the PHP 5.1.0, this function will return a failure-1.
Now let's take a look at the strtotime character conversion to the time function instance, the code is as follows:
The code is as follows:
<?php//function function Nextweeksday ($date _begin, $nbrweek) {$nextweek = Array (); for ($i = 1; $i <= $nbrweek; $i + +) {//week in one year of coursewww.phpfensi.com $nextweek [$i]=date (' d d M Y ', str ToTime (' + '. $i. ' Week ', $date _begin)); } return $nextweek; }///End Function///example of a Select date//var $date _begin = strtotime (' 06-05-2010 '); D Day Month year-like function format. $nbrweek = 52; Call function $result =nextweeksday ($date _begin, $nbrweek); Preview for ($i = 1; $i <= $nbrweek; $i + +) {echo ' <br>-'. $result [$i];};
<?php $str = ' not good '; Previous to PHP 5.1.0 you would compare with-1, instead of false if (($timestamp = Strtotime ($str)) = = = = False) { E Cho "the string ($STR) is bogus"; } else { echo "$str = =". Date (' l DS o F Y h:i:s A ', $timestamp); }?> <?php echo strtotime ("Now"), ""; Echo Strtotime ("Ten September 2000"), ""; Echo strtotime ("+1 Day"), ""; Echo strtotime ("+1 Week"), ""; Echo strtotime ("+1 Week 2 days 4 hours 2 Seconds"), ""; Echo Strtotime ("next Thursday"), ""; Echo Strtotime ("Last Monday"), "";?>
This is a fast function calculation during the year, "Working days", "workdays" are those that do not have weekends, no holidays specified in the $ array of holidays, the instance code is as follows:
The code is as follows:
function get_working_days ($to _date) {$holidays = array (1 = = Array (10 ),//2011 ... 2 = = Array (one), 3 = = Array (21),//... 4 = Array (29,30),//2010 ... 5 = = Array (3,4,5), 6 = = Array (), 7 = = Array (8), Array (11,12,13), 9 = Array (20,23), ten = = Array (one), one by one (3,23), and the array (23)//... 2010); For ($to _date, $w = 0, $i = 0, $x = time (), $x < $to _date, $i + +, $x = Strtotime ("+ $i Day")) {if (Date ("N", $x) < ; 6 &! In_array (Date ("J", $x), $holidays [Date ("n", $x)]) $w + +; } return $w; }//usage:echo Get_working_days (Strtotime ("2011-01-08"));