Detailed description of strtotime function usage in php and strtotime. The strtotime function usage in php is described in detail, and the strtotime function usage in php is described in this article. Share it with you for your reference. Details are as follows: strtotime (string $ time [, detailed description of strtotime function usage in php, detailed description of strtotime
This example describes the usage of strtotime in php. Share it with you for your reference. The details are as follows:
Strtotime (string $ time [, meaning $ now]) int strtotime (string $ time [, int $ now] This function is expected to get a date format that contains American English, and will try to parse it into a Unix timestamp (the number of seconds since 00:00:00 Monday, January 1, January 1, 1970), relative to the current timestamp, or if the current time is not provided
This function uses the TZ environment variable (if any) to calculate the timestamp. PHP 5.1.0 has an easier way to determine the time zone of All/dateTime functions used, this process is explained on the page of the date_default_timezone_get () function.
The parsed strings in PHP 5.0.0 are not allowed in microseconds. they are allowed from PHP 5.0.0, but ignored.
Which of the following timestamps are used as the calculation base relative to the date.
Returned value: a timestamp is returned successfully. otherwise, FALSE is returned. the previous value is PHP 5.1.0. This function will return failure-1.
Now let's take a look at the function instance for converting strtotime to time. 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 ++) {// 52 week in one year of coursewww.phpfensi.com
$ Nextweek [$ I] = date ('d d m y ', strtotime (' + '. $ 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'
-'. $ Result [$ I];
}
?>
<? 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 o f y h: I: s A', $ timestamp );
}
?>
<? Php
Echo strtotime ("now "),"";
Echo strtotime ("10 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 compute period of one year, "working days", "working days" refers to those without weekends, no holidays in the $ array specified 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 (11 ),
3 => array (21), //... 2011
4 => array (2010...
5 => array (3, 4, 5 ),
6 => array (),
7 => array (19 ),
8 => array (11,12, 13 ),
9 => array (20, 23 ),
10 => array (11 ),
11 => array (3, 23 ),
12 => 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 "));
I hope this article will help you with PHP programming.
Examples in this article describes how to use the strtotime function in php. Share it with you for your reference. Details: strtotime (string $ time [,...