PHP time and date processing and sorting
Release: 2016-07-25 08:43:48
Original
780 people have browsed it
- //Return the timestamps of all months in a time period
-
- function monthList($start,$end){
- if(!is_numeric($start)||!is_numeric($end)||($end< ;=$start)) return '';
- $start=date('Y-m',$start);
- $end=date('Y-m',$end);
- //Convert to timestamp
- $start=strtotime($start.'-01');
- $end=strtotime($end.'-01');
- $i=0;
- $d=array();
- while($start<= $end){
- //The calculation formula for the total number of seconds accumulated in each month is: the timestamp seconds on the 1st of the previous month minus the timestamp seconds of the current month
- $d[$i]=trim(date ('Y-m',$start),' ');
- $start+=strtotime('+1 month',$start)-$start;
- $i++;
- }
- return $d;
-
- }
-
- //Return the start and end dates of the week within a time period by passing date type
-
- function monthList($start,$end){
- if(!is_numeric($start)||!is_numeric($end)||($end< ;=$start)) return '';
- $start=date('Y-m',$start);
- $end=date('Y-m',$end);
- //Convert to timestamp
- $start=strtotime($start.'-01');
- $end=strtotime($end.'-01');
- $i=0;
- $d=array();
- while($start<= $end){
- //The calculation formula for the total number of seconds accumulated in each month is: the timestamp seconds on the 1st of the previous month minus the timestamp seconds of the current month
- $d[$i]=trim(date ('Y-m',$start),' ');
- $start+=strtotime('+1 month',$start)-$start;
- $i++;
- }
- return $d;
- }
-
- / /Return the first and last day of a month
-
- function getthemonth($date)
- {
- $firstday = date('Y-m-01', strtotime($date));
- $lastday = date('Y-m-d ', strtotime("$firstday +1 month -1 day"));
- return array($firstday,$lastday);
- }
- $today = date("Y-m-d");
- $day=getthemonth($today) ;
Copy code
|
PHP
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31