If the system does not set the time zone, the result is UTC time. Compared with Chinese users, the difference is 8 hours. & amp; lt ;? PhpclassDate {*** get or set the time zone ** @ paramint $ timezone time zone * @ returnstring | bool * publicstaticfunc... if the system does not set the time zone, the result is UTC time, which is 8 hours different from that of Chinese users.
23) |! $ Hs24 & ($ h <1 | $ h> 12) return false; if ($ m> 59 | $ m <0) return false; if ($ s> 59 | $ s <0) return false; return true ;} /*** check whether the time is valid * @ param integer $ time * @ param string $ separator * @ return boolean true if valid date, semantic check only. * @ since 1.0.5 */public static function checkTime ($ time, $ separator = ":") {$ timeArr = explode ($ separator, $ time); return self: isValidTime ($ TimeArr [0], $ timeArr [1], $ timeArr [2]);}/*** get timestamp ** @ param int $ dateTime is empty by default, returns * @ return int */public static function getTimeStamp ($ dateTime = null) {return $ dateTime? Is_numeric ($ dateTime )? $ DateTime: strtotime ($ dateTime): time () ;}/ *** format the output ** @ param string $ format the target format, if it is null by default, the * @ param int $ dateTime Unix timestamp is output in Y-m-d H: I: s format, if it is null by default, the current timestamp * @ return string */public static function format ($ format = null, $ dateTime = null) {return date ($ format? $ Format: 'Y-m-d H: I: S', self: getTimeStamp ($ dateTime ));} /*** get the week ** @ param string $ date * @ return int */public static function getWeekNum ($ date, $ separator = "-") {$ dateArr = explode ($ separator, $ date); return date ("w", mktime (0, 0, 0, $ dateArr [1], $ dateArr [2], $ dateArr [0]);}/*** get week ** @ param int $ week, get * @ return string */public static function getWeek ($ week = null) at the current time by default) {$ Week = $ week? $ Week: self: format ('w'); $ weekArr = array ('Sunday', 'Monday', 'Tuesday', 'weday', 'thurday ', 'Friday', 'Saturday'); return $ weekArr [$ week];}/*** determine whether it is a leap year ** @ param int $ year, the default value is the current year * @ return bool */public static function isLeapYear ($ year = null) {$ year = $ year? $ Year: self: format ('Y'); return ($ year % 4 = 0 & $ year % 100! = 0 | $ year % 400 = 0);}/*** obtain the number of days in a year * @ param int $ year, the default value is the current year */public static function getDaysInYear ($ year = null) {$ year = $ year? $ Year: self: format ('Y'); return self: isLeapYear ($ year )? 366: 365;}/*** get the time period of the day ** @ param int $ hour, the default value is the current hour * @ return string */public static function getPeriodOfTime ($ hour = null) {$ hour = $ hour? $ Hour: self: format ('g'); $ period = null; if ($ hour> = 0 & $ hour <6) {$ period = 'Early morning ';} elseif ($ hour >=6 & $ hour <8) {$ period = 'Morning ';} elseif ($ hour> = 8 & $ hour <11) {$ period = 'AM ';} elseif ($ hour> = 11 & $ hour <13) {$ period = 'Midday ';} elseif ($ hour >=13 & $ hour <15) {$ period = 'Noon ';} elseif ($ hour >=15 & $ hour <18) {$ period = 'amount';} elseif ($ hour >=18 & $ hour <20 ){ $ Period = 'evening ';} elseif ($ hour >=20 & $ hour <22) {$ period = 'evening ';} elseif ($ hour >=22 & $ hour <= 23) {$ period = 'Late Night ';} return $ period;} public static function timeFromNow ($ dateline) {if (empty ($ dateline) return false; $ seconds = time ()-$ dateline; if ($ seconds <60) {return "1 minute ago ";} elseif ($ seconds <3600) {return floor ($ seconds/60 ). "minutes ago";} elseif ($ seconds <24*3600) {r Eturn floor ($ seconds/3600 ). "hours ago";} elseif ($ seconds <48*3600) {return date ("yesterday H: I", $ dateline ). "";} else {return date ('Y-m-D', $ dateline);}/*** convert the date number to Chinese, applicable to the number of days, months, and weeks * @ param int $ day. the default value is the current date * @ return string */public static function numberToChinese ($ number) {$ chineseArr = array ('1', '2', '3', '4', '5', '6', '7', '8 ', '9', '10'); $ chineseStr = null; if ($ number <10) {$ chinese Str = $ chineseArr [$ number-1];} elseif ($ number <20) {$ chineseStr = '10 '. $ chineseArr [$ number-11];} elseif ($ number <30) {$ chineseStr = '20 '. $ chineseArr [$ number-21];} else {$ chineseStr = '30 '. $ chineseArr [$ number-31];} return $ chineseStr;}/*** convert year numbers to Chinese ** @ param int $ year numbers, the default value is the current year * @ return string */public static function yearToChinese ($ year = null, $ flag = false) {$ yea R = $ year? Intval ($ year): self: format ('Y'); $ data = array ('0', '1', '2', '3 ', '4', '5', '6', '7', '8', '9'); $ chineseStr = null; for ($ I = 0; $ I <4; $ I ++) {$ chineseStr. = $ data [substr ($ year, $ I, 1)];} return $ flag? 'Ad '. $ chineseStr: $ chineseStr;}/*** obtain the constellation, Ganzhi, and zodiac of the date ** @ param string $ type to obtain the information type (SX: Zodiac, GZ: ganzhi, XZ: Constellation) * @ return string */public static function dateInfo ($ type, $ date = null) {$ year = self: format ('Y ', $ date); $ month = self: format ('M', $ date); $ day = self: format ('D', $ date ); $ result = null; switch ($ type) {case 'sx ': $ data = array ('Rat', 'ox ', 'Tiger', 'rabbit ', 'Long', 'Snake ', 'ma', 'Yang', 'Monkey', 'Chicken ', 'dog', 'Pig '); $ Result = $ data [($ year-4) % 12]; break; case 'gz': $ data = array ('A ', 'B', 'Bing', 'ding', 'pente', 'Ji ', 'geng', 'sin', 'Taobao', 'cuy '), array ('child ', 'Ugly', 'yin ', 'Mao', 'Chen ', 'Si', 'Wu ', 'Wei', 'Shen ', 'uni', 'hour', 'Hai'); $ num = $ year-1900 + 36; $ result = $ data [0] [$ num % 10]. $ data [1] [$ num % 12]; break; case 'xz ': $ data = array ('capricorn', 'baby bottle ', 'pisces', 'aries ', 'Taurus ', 'gemine', 'Cancer', 'Lions ', 'virgins', 'Libra ', 'Scorpio', 'Sagittarius '); $ zone = array (1222, 122,222,321,421,522,622,722,822,922,102 2, 1122,122 2); if (100 * $ month + $ day) >=$ zone [0] | (100 * $ month + $ day) <$ zone [1]) {$ I = 0;} else {for ($ I = 1; $ I <12; $ I ++) {if (100 * $ month + $ day) >=$ zone [$ I] & (100 * $ month + $ day) <$ zone [$ I + 1]) break; }}$ result = $ data [$ I]. 'seat '; break;} return $ result;}/*** get the difference between two dates ** @ param string $ interval the interval type of the date difference, (Y: year, M: Month, W: Star Period, D: Date, H: Hour, N: minute, S: Second) * @ param int $ startDateTime start date * @ param int $ endDateTime end date * @ return int */public static function dateDiff ($ interval, $ startDateTime, $ endDateTime) {$ diff = self: getTimeStamp ($ endDateTime)-self: getTimeStamp ($ startDateTime); switch ($ interval) {case 'Y ': // year $ result = bcp ($ diff, 60*60*24*365); break; case 'm': // month $ result = bcp ($ diff, 60*60*24*30); break; Case 'w': // day of the week $ result = bcp ($ diff, 60*60*24*7); break; case 'D ': // day $ result = bcp ($ diff, 60*60*24); break; case 'H': // hour $ result = bcp ($ diff, 60*60); break; case 'n': // minute $ result = bcp ($ diff, 60); break; case 'S': // second default: $ result = $ diff; break;} return $ result;}/*** return the date of the specified date after the specified time interval ** @ param string $ interval time interval type, (Y: year, Q: Quarter, M: Month, W: Week, D: Date, H: Hour, N: minute, S: second) * @ param int $ va Lue time interval value. The value is positive to obtain the future time, if the value is a negative number, obtain the past time * @ param string $ dateTime date * @ param string $ format returns the date conversion format * @ return string returns the appended date */public static function dateAdd ($ interval, $ value, $ dateTime = null, $ format = null) {$ dateTime = $ dateTime? $ DateTime: self: format (); $ date = getdate (self: getTimeStamp ($ dateTime); switch ($ interval) {case 'Y ': // year $ date ['Year'] + = $ value; break; case 'Q ': // quarter $ date ['mon'] + = ($ value * 3); break; case'm ': // month $ date ['mon'] + = $ value; break; case 'w ': // day of the week $ date ['mday'] + = ($ value * 7); break; case 'D ': // day $ date ['mday'] + = $ value; break; case 'H': // hour $ date ['hours'] + = $ value; break; case 'n': // minute $ Date ['minutes '] + = $ value; break; case 'S': // second default: $ date ['seconds'] + = $ value; break ;} return self: format ($ format, mktime ($ date ['hours'], $ date ['minutes '], $ date ['seconds'], $ date ['mon'], $ date ['mday'], $ date ['Year']);} /*** obtain the number of days per month based on the year ** @ param int $ year * @ return array month number of days array */public static function getDaysByMonthsOfYear ($ year = null) {$ year = $ year? $ Year: self: format ('Y'); $ months = array (31, 28, 31, 30, 31, 30, 31, 31, 30, 30, 31); if (self: isLeapYear ($ year) $ months [1] = 29; return $ months ;} /*** returns the number of days of a month in a certain year. ** @ param int $ month * @ param int $ year * @ return int month days */public static function getDaysByMonth ($ month, $ year) {$ months = self: getDaysByMonthsOfYear ($ year); $ value = $ months [$ month-1]; return! $ Value? 0: $ value ;} /*** get the first day of the year ** @ param int $ year * @ param int $ format returned date format * @ return string returned date */public static function firstDayOfYear ($ year = null, $ format = 'Y-m-D') {$ year = $ year? $ Year: self: format ('Y'); return self: format ($ format, mktime (0, 0, 0, 1, 1, $ year ));} /*** get the last day of the year ** @ param int $ year * @ param int $ format returned date format * @ return string returned date */public static function lastDayOfYear ($ year = null, $ format = 'Y-m-D') {$ year = $ year? $ Year: self: format ('Y'); return self: format ($ format, mktime (0, 0, 0, 1, 0, $ year + 1 ));} /*** obtain the first day of a month ** @ param int $ month * @ param int $ year * @ param int $ format returned date format * @ return string returned date */ public static function firstDayOfMonth ($ month = null, $ year = null, $ format = 'Y-m-D') {$ year = $ year? $ Year: self: format ('Y'); $ month = $ month? $ Month: self: format ('M'); return self: format ($ format, mktime (0, 0, 0, $ month, 1, $ year ));} /*** obtain the last day of a month ** @ param int $ month * @ param int $ year * @ param int $ format returned date format * @ return string returned date */ public static function lastDayOfMonth ($ month = null, $ year = null, $ format = 'Y-m-D') {$ year = $ year? $ Year: self: format ('Y'); $ month = $ month? $ Month: self: format ('M'); return self: format ($ format, mktime (0, 0, 0, $ month + 1, 0, $ year ));} /*** get the range between two dates ** @ param string $ startDateTime * @ param string $ endDateTime * @ param string $ format * @ return array returns the date array */public static function getDayRangeInBetweenDate ($ startDateTime, $ endDateTime, $ sort = false, $ format = 'Y-m-D') {$ startDateTime = self: getTimeStamp ($ startDateTime); $ endD AteTime = self: getTimeStamp ($ endDateTime); $ num = ($ endDateTime-$ startDateTime)/86400; $ dateArr = array (); for ($ I = 0; $ I <= $ num; $ I ++) {$ dateArr [] = self: format ($ format, $ startDateTime + 86400 * $ I);} return $ sort? Array_reverse ($ dateArr): $ dateArr ;}} if (! Function_exists ('bcp') {function bcp ($ first, $ second, $ scale = 0) {$ res = $ first/$ second; return round ($ res, $ scale );}}