PHP date Mktime Strtotime Get Time method
- /**
- * Get an array of system years
- */
- function Getsystemyeararr () {
- $year _arr = Array (' + ' + ') ', ' + ' ' + ', ' ' + ', ' ' ' ' ' ', ' ' ' ' + ' 2014 ', ' + ' = ' + ', ' + ' + ', ' ' ~ ' and ' ', ' 2018 ' = ' 2018 ', ' 2019 ' and ' 2019 ', ' 2020 ' and ' 2020 ');
- return $year _arr;
- }
- /**
- * Get System Month array
- */
- function Getsystemmontharr () {
- $month _arr = Array (' 1 ' = ' ~ ', ' 2 ' = ' + '), ' 3 ' = ' ", ' 4 ' = '", ' 5 ' = ' ', ' 6 ' + ' ', ' 7 ' = ' 07 ', ' 8 ' + ', ' 9 ' = '-' ', ' ' + ', ' + ', ' one ' and ' one ', ' one ', ' 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;
- }
- /**
- * Get the week array of the system month, the first week insufficient need to complement
- */
- function Getmonthweekarr ($current _year, $current _month) {
- The first day of the month
- $firstday = Strtotime ($current _year. '-'. $current _month. '-01 ');
- A few days in the first week of the month
- $firstweekday = (7-date (' N ', $firstday) + 1);
- Calculate the time of the first Monday of the month
- $starttime = $firstday -3600*24* (7-$firstweekday);
- The last day of the month
- $lastday = Strtotime ($current _year. '-'. $current _month. ' -01 '. "+1 month-1 Day");
- The last week of the month is a few days
- $lastweekday = Date (' N ', $lastday);
- 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 start and end times for 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 day, the first 3 days, this week, this month, this year's time
- echo Date ("Y-m-d", mktime (0, 0, 0,date ("M"), Date ("D"), date ("Y")) -86400*3); Current date pushed forward 3 days
- thinkphp Check the day, this week, this month, this year's time
- $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 get last week, this week, last month, this month, this quarter, last quarter time method Daquan
- 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 "********* months:";
- echo Date (' n ');
- echo "********* Week of the week:";
- Echo Date ("W");
- echo "********* Days of the Month:";
- echo Date ("T");
- echo "*********";
- Echo '
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 the 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 start 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 the 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);//The month of the first quarter
- Echo '
Starting time of the 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;//quarter of last quarter
- Echo '
Last quarter start time: ';
- 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 |