HP calculates the number of weeks of a year, and returns the start time and end time of a week (optional, return the timestamp or date)
- Function getWeekStartAndEnd ($ year, $ week = 1 ){
- Header ("Content-type: text/html; charset = utf-8 ");
- Date_default_timezone_set ("Asia/Shanghai ");
- $ Year = (int) $ year;
- $ Week = (int) $ week;
- // Calculate the total number of weeks of the current year based on the given year
- $ Date = new DateTime;
- $ Date-> setISODate ($ year, 53 );
- $ Weeks = max ($ date-> format ("W"), 52 );
- // If the specified number of weeks is greater than the total number of weeks or less than or equal to 0
- If ($ week> $ weeks | $ week <= 0 ){
- Return false;
- }
- // If the number of weeks is less than 10
- If ($ week <10 ){
- $ Week = '0'. $ week;
- }
- // The start and end timestamp of the week
- $ Timestamp ['start'] = strtotime ($ year. 'W'. $ week );
- $ Timestamp ['end'] = strtotime ('+ 1 week-1 Day', $ timestamp ['start']);
- // Start and end dates of the week
- $ Timeymd ['start'] = date ("Y-m-d", $ timestamp ['start']);
- $ Timeymd ['end'] = date ("Y-m-d", $ timestamp ['end']);
- // Returns the start timestamp.
- Return $ timestamp;
- // Return Date format
- // Return $ timeymd;
- }
|
(Optional) number of instances in a week