php date mktime strtotime get time method
-
/**
- * Get the system year array
- */
- function getSystemYearArr(){
- $year_arr = array('2010'=>'2010','2011'=>'2011',' 2012'=>'2012','2014'=>'2014','2014'=>'2014','2015'=>'2015','2016'=>'2016',' 2017'=>'2017','2018'=>'2018','2019'=>'2019','2020'=>'2020');
- return $year_arr;
- }
- /* *
- * Get the system month array
- */
- function getSystemMonthArr(){
- $month_arr = array('1'=>'01','2'=>'02','3'=>'03','4 '=>'04','5'=>'05','6'=>'06','7'=>'07','8'=>'08','9 '=>'09','10'=>'10','11'=>'11','12'=>'12');
- return $month_arr;
- }
- /**
- * Get system week array
- */
- function getSystemWeekArr(){
- $week_arr = array('1'=>'Monday','2'=>'Tuesday','3'=>'Wednesday','4' =>'Thursday','5'=>'Friday','6'=>'Saturday','7'=>'Sunday');
- return $week_arr;
- }
- /**
- * Get the last day of a month
- */
- function getMonthLastDay($year, $month){
- $t = mktime(0, 0, 0, $month + 1, 1, $year);
- $t = $t - 60 * 60 * 24;
- return $t;
- }
- /**
- * Obtain the week number of a certain month in the system. If the first week is insufficient, it needs to be made up
- */
- function getMonthWeekArr($current_year, $current_month){
- //The first day of the month
- $firstday = strtotime($current_year.' -'.$current_month.'-01');
- //How many days are there in the first week of the month
- $firstweekday = (7 - date('N',$firstday) +1);
- //Calculate the month The time of the first Monday
- $starttime = $firstday-3600*24*(7-$firstweekday);
- //The last day of the month
- $lastday = strtotime($current_year.'-'.$current_month.'- 01'." +1 month -1 day");
- //The number of days in the last week of the month
- $lastweekday = date('N',$lastday);
- //The time of the last weekend of the month
- $endtime = $lastday-3600*24*$lastweekday;
- $step = 3600*24*7;//Step value
- $week_arr = array();
- for ($i=$starttime; $i<$endtime ; $i= $i+3600*24*7){
- $week_arr[] = array('key'=>date('Y-m-d',$i).'|'.date('Y-m-d ',$i+3600*24*6), 'val'=>date('Y-m-d',$i).'~'.date('Y-m-d',$i+3600*24*6 ));
- }
- return $week_arr;
- }
- /**
- * Get the start time and end time of the week
- */
- function getWeek_SdateAndEdate($current_time){
- $current_time = strtotime(date('Y-m-d',$current_time));
- $ return_arr['sdate'] = date('Y-m-d', $current_time-86400*(date('N',$current_time) - 1));
- $return_arr['edate'] = date('Y-m-d ', $current_time+86400*(7- date('N',$current_time)));
- return $return_arr;
- }
- //Query the time of the day, the previous 3 days, this week, this month, and this year
- echo date("y-m-d",mktime(0, 0, 0,date("m"),date("d"),date("Y"))-86400*3); //The current date is pushed forward by 3 Day
- //thinkphp queries the time of the day, this week, this month, and this year
- $time=I('get.time');
- switch ($time) {
- case 'day':
- $startTime=date ("Y-m-d");
- $endTime=date("Y-m-d");
- break;
- case 'week':
- $startTime=date("Y-m-d",mktime(0, 0 , 0,date("m") ,date("d")-date("w")+1,date("Y")));
- $endTime =date("Y-m-d",mktime(23,59,59,date("m") ,date("d")-date("w")+7,date("Y")));
- break;
- case 'month':
- $startTime = date("Y-m-d",mktime(0, 0 , 0,date("m"),1,date("Y")));
- $endTime=date("Y-m-d",mktime(23,59,59,date("m"),date("t "),date("Y")));
- break;
- case 'year':
- $startTime=date("Y").'-01-01';
- $endTime=date("Y"). '-12-31';
- break;
- default:
- break;
- }
- //Other ways to get PHP to get the complete list of time methods for last week, this week, last month, this month, this quarter, and last quarter
- echo date("Ymd",strtotime("now")), "n";
- echo date("Ymd",strtotime("-1 week Monday")), "n";
- echo date("Ymd",strtotime("-1 week Sunday")), "n";
- echo date(" Ymd",strtotime("+0 week Monday")), "n";
- echo date("Ymd",strtotime("+0 week Sunday")), "n";
- echo "***** ****The month:";
- echo date('n');
- echo "*********Day of the week:";
- echo date("w");
- echo "*********Days of this month:";
- echo date("t");
- echo "**********";
- echo '
Since last week Start time: ';
- echo date("Y-m-d H:i:s",mktime(0, 0, 0,date("m"),date("d")-date("w") +1-7,date("Y"))),"n";
- echo date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d ")-date("w")+7-7,date("Y"))),"n";
- echo '
Starting time of this week: ';
- echo date( "Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),date("d")-date("w")+1,date("Y")))," n";
- echo date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-date("w")+7,date(" Y"))),"n";
- echo '
Last month's starting time: ';
- echo date("Y-m-d H:i:s",mktime(0, 0 , 0 ,date("m")-1,1,date("Y"))),"n";
- echo date("Y-m-d H:i:s",mktime(23,59,59,date("m "),0,date("Y"))),"n";
- echo '
Starting time of this month: ';
- echo date("Y-m-d H:i:s", mktime(0, 0, 0,date("m"),1,date("Y"))),"n";
- echo date("Y-m-d H:i:s",mktime(23,59,59 ,date("m"),date("t"),date("Y"))),"n";
- $season = ceil((date('n'))/3);//Current month Which quarter is it
- echo '
Starting time of this quarter: ';
- echo date('Y-m-d H:i:s', mktime(0, 0, 0,$season*3-3 +1,1,date('Y'))),"n";
- echo date('Y-m-d H:i:s', mktime(23,59,59,$season*3,date('t', mktime(0, 0, 0,$season*3,1,date("Y"))),date('Y'))),"n";
- $season = ceil((date('n' ))/3)-1;//What quarter was the last quarter?
- echo '
Start time of last quarter: ';
- echo date('Y-m-d H:i:s', mktime( 0, 0, 0,$season*3-3+1,1,date('Y'))),"n";
- echo date('Y-m-d H:i:s', mktime(23,59,59 ,$season*3,date('t',mktime(0, 0, 0,$season*3,1,date("Y"))),date('Y'))),"n";
Copy code
|