? Phpdate_default_timezone_set (#39; prc #39;); * calculate the date after a certain number of days from a day ,...
0) {// make up the whole week $ tmp = $ weekday + $ remain; if ($ tmp >=7) {$ newoffset + = 2 ;} else if ($ tmp = 6) {$ newoffset + = 1;} // consider the current situation of Saturday and Sunday if ($ weekday = 6) {$ newoffset-= 1;} else if ($ weekday = 7) {$ newoffset-= 2 ;}} // calculate the offset if (is_array ($ exception) {// multiple holidays foreach ($ exception as $ day) {$ tmp_time = strtotime ($ day ); if ($ tmp_time> $ starttime & $ tmp_time <= $ endtime) {// within the range (a, B] $ weekday_t = dat E ('N', $ tmp_time); if ($ weekday_t <= 5) {// prevent repeated holidays and weekends $ newoffset + = 1 ;}}}} else {// single holiday if ($ exception! = '') {$ Tmp_time = strtotime ($ exception); if ($ tmp_time> $ starttime & $ tmp_time <= $ endtime) {$ weekday_t = date ('N ', $ tmp_time); if ($ weekday_t <= 5) {$ newoffset + = 1 ;}}// based on the offset days, recursive equivalent operation 111cn.net if ($ newoffset> 0) {# echo "[{$ start}-> {$ offset}] = [{$ end}-> {$ newoffset}]"."
"; Return getendday ($ end, $ newoffset, $ exception, $ allow);} else {return $ end ;}} /*** method of violent loop */function getendday2 ($ start = 'Now ', $ offset = 0, $ exception = '', $ allow = '') {$ starttime = strtotime ($ start); $ tmptime = $ starttime + 24*3600; while ($ offset> 0) {$ weekday = date ('N ', $ tmptime); $ tmpday = date ('Y-m-D', $ tmptime); $ bfd = false; // whether it is a holiday if (is_array ($ exception )) {$ bfd = in_array ($ tmpday, $ excep Tion);} else {$ bfd = ($ exception = $ tmpday);} if ($ weekday <= 5 &&! $ Bfd) {// not a weekend or holiday $ offset --; # echo "tmpday = {$ tmpday }"."
";}$ Tmptime + = 24*3600;} return $ tmpday ;}$ exception = array ('2017-01-01 ', '2017-01-02', '2017-01-03 ', '2017-04-03 ', '2017-04-04', '2017-04-05 ', '2017-05-01', '2017-05-02 ', '2017-05-03 ', '2017-06-14 ', '2017-06-15', '2017-06-16 ', '2017-09-22', '2017-09-23 ', '2017-09-24 ', '2017-10-01 ', '2017-10-02', '2017-10-03 ', '2017-10-04', '2017-10-05 ', '2017-10-06 ', '2017-10-07',); // echo getendday ('2017-08-27 ', 3, ''); // echo getendday ('2017-06-25', 15, '2017-07-07 '); $ t1 = microtime (); echo getendday ('2017-05-12', 66, $ exception )."
"; $ T2 = microtime (); echo" use ". ($ t2-$ t1)." s
"; Echo getendday2 ('2017-05-12 ', 66, $ exception )."
"; $ T3 = microtime (); echo" use ". ($ t3-$ t2)." s
";
Permanent link:
Reprint at will! Include the article address.