今天就跟大家聊聊有關(guān)php中怎么實現(xiàn)一個時間助手類,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。
十余年的迎江網(wǎng)站建設(shè)經(jīng)驗,針對設(shè)計、前端、開發(fā)、售后、文案、推廣等六對一服務(wù),響應(yīng)快,48小時及時工作處理。網(wǎng)絡(luò)營銷推廣的優(yōu)勢是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動調(diào)整迎江建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計,從而大程度地提升瀏覽體驗。創(chuàng)新互聯(lián)從事“迎江網(wǎng)站設(shè)計”,“迎江網(wǎng)站推廣”以來,每個客戶項目都認真落實執(zhí)行。
<?php namespace Helper; use app\common\model\Holiday; class DateHelper { /** * PHP計算兩個時間段是否有交集(邊界重疊不算) * @param string $beginTime1 開始時間1 * @param string $endTime1 結(jié)束時間1 * @param string $beginTime2 開始時間2 * @param string $endTime2 結(jié)束時間2 * @return bool */ public static function isTimeCross($beginTime1 = '', $endTime1 = '', $beginTime2 = '', $endTime2 = ''){ $status = $beginTime2 - $beginTime1; if ($status > 0){ $status2 = $beginTime2 - $endTime1; if ($status2 > 0){ return false; }elseif ($status2 < 0){ return true; }else{ return false; } }elseif($status < 0){ $status2 = $endTime2 - $beginTime1; if ($status2 > 0){ return true; }else if ($status2 < 0){ return false; }else{ return false; } }else{ $status2 = $endTime2 - $beginTime1; if ($status2 == 0){ return false; }else{ return true; } } } /** * 時間天數(shù)差 * @param $day1 * @param $day2 * @return float|int */ public static function diffBetweenTwoDays($day1, $day2) { $second1 = strtotime($day1); $second2 = strtotime($day2); if ($second1 < $second2) { $tmp = $second2; $second2 = $second1; $second1 = $tmp; } return ceil($second1 - $second2) / 86400; } /** * 時間格式化 * @param $date * @param string $format * @return false|string */ public static function dataFormat($date, $format = 'Y-m-d') { $date = is_numeric($date) ? $date : strtotime($date); return !$format ? $date : date($format, $date); } /** * 是否工作日 * @param $date * @return bool */ public static function isWorkingDay($date) { if (self::isWeekend($date)) { return false; } if (self::isHoliday($date)) { return false; } return true; } /** * 是否周末 * @param $date * @return bool */ public static function isWeekend($date) { return in_array(self::dataFormat($date,'w'),[6,0]); } /** * 是否節(jié)假日 * @param $date * @param bool $currentYear * @return bool */ public static function isHoliday($date,$currentYear = true) { $holiday = $currentYear ? Holiday::where('year','=',self::dataFormat($date,'Y'))->column('id','holiday_date') : Holiday::column('id','holiday_date'); return empty($holiday[self::dataFormat($date,'Y-m-d')]) ? false : true; } /** * 結(jié)束時間格式化 * @param $date * @param string $format * @return string */ public static function dateFormatOfEndTime($date, $format = 'Y-m-d') { $date = is_numeric($date) ? $date : strtotime($date); return date($format, $date) . ' 23:59:59'; } /** * 獲取多少天前的日期 * @param $date * @param $days * @param string $format * @return false|float|int|string */ public static function getBeforeDate($date, $days, $format = '') { $date = is_numeric($date) ? $date : strtotime($date); $date = $date - $days * 3600 * 24; return $format ? date($format, $date) : $date; } }
看完上述內(nèi)容,你們對php中怎么實現(xiàn)一個時間助手類有進一步的了解嗎?如果還想了解更多知識或者相關(guān)內(nèi)容,請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝大家的支持。
文章名稱:php中怎么實現(xiàn)一個時間助手類
URL網(wǎng)址:http://muchs.cn/article32/pidppc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制網(wǎng)站、品牌網(wǎng)站建設(shè)、網(wǎng)站策劃、手機網(wǎng)站建設(shè)、網(wǎng)站制作、微信小程序
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)