phpDate() function outputs Chinese year, month, day, hour, minute and second_PHP tutorial
Today I will use a simple method of using the date() function to output the Chinese year, month, day, hour, minute and second to elicit some problems that most data users have when using the php date() function and provide a detailed explanation of some parameters of the date() function. Of course, it is impossible for PHP’s DATE function to directly output the Chinese year, month and day, but you can use the following method to write a function yourself. The code is as follows function today(){ date_default_timezone_set (“Asia/Chongqing”); $a=date(“Y”); $b=date(“m”); $c=date(“d”); $d=date(“G”); $e=date(“i”); $f=date(“s”); return $a.’Year’.$b.’Month’.$c.’Day’.$d.’Hour’.$e.’Minute’.$f.’Second’;} If echo date(“Y-m-d”); Warning number: Warning: date() [function.date]: It is not safe to rely on the system’s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set () function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘UTC’ for ‘8.0/no DST’ instead in G:sourcetestceshimktime.php on line 4 After checking the information online, I found out the reason. I will share it with you below: When using PHP versions above PHP5.3, as long as it involves time, one will be reported “PHP Warning: date() [function.date]:…
PHP calculates the time difference between two dates (returns year, month, day)_PHP tutorial
In PHP programs, we often encounter processing time problems, such as: determining how long a user has been online, how many days they have been logged in, the time difference between two posts or log records between different operations, etc. In the article, a simple example is given of how to calculate the year, month, and day difference between two dates in PHP. strtotime($date2)) { $ymd = $date2; $date2 = $date1; $date1 = $ymd; } list($y1, $m1, $d1) = explode(‘-‘, $date1); list($y2, $m2, $d2) = explode(‘-‘, $date2); $y = $m = $d = $_m = 0; $math = ($y2 – $y1) * 12 + $m2 – $m1; $y = round($math / 12); $m = intval($math % 12); $d = (mktime(0, 0, 0, $m2, $d2, $y2) – mktime(0, 0, 0, $m2, $d1, $y2)) / 86400; if ($d <0) { $m -= 1; $d += date('j', mktime(0, 0, 0, $m2, 0, $y2)); } $m http://www.bkjia.com/PHPjc/825387.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/825387.htmlTechArticleIn PHP programs, we often encounter processing time problems, such as: determining how long a user has been online, how many days they have been logged in, the time difference between two posts or different operations…
The phpDate() function outputs the Chinese year, month, day, hour, minute and second, _PHP tutorial
php Date() function outputs the Chinese year, month, day, hour, minute and second, Of course, it is impossible for PHP’s DATE function to directly output the Chinese year, month, day, but you can use the following This method writes a function yourself. The code is as followsfunction today(){ date_default_timezone_set (“Asia/Chongqing”); $a=date(“Y”); $b=date( “m”); $c=date(“d”); $d=date(“G”); $e=date(“i”); $f=date(“s”);return $a.’Year’.$b.’Month’.$c.’Day’.$d.’Hour’.$e.’Min’ .$f.’second’;} If echo date(“Y-m-d”); Warning signal: Warning: date() [function.date]: It is not safe to rely on the system’s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘UTC’ for ‘8.0/no DST’ instead in G:sourcetestceshimktime.php on line 4Checked the information online Now that I know the reason, I will share it with you:When using PHP version 5.3 or above, as long as it involves time, a report will be reported “PHP Warning: date() [function .date]: It is not safe to rely on the system’s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning ,…
PHP gets the year, month, day, hour, minute, and second between the specified time period, php gets_PHP tutorial
PHP obtains the year, month, day, hour, minute, and second between the specified time periods, php obtains Core code: Class Utils { /** * format MySQL DateTime (YYYY-MM-DD hh:mm:ss) converts the data format found in mysql into time seconds * @param string $datetime */ public function fmDatetime($datetime) { $year = substr($datetime,0,4); $mOnth= substr($datetime,5,2); $day = substr($datetime,8,2); $hour = substr($datetime,11,2); $min = substr($datetime,14,2); $sec = substr($datetime,17,2); return mktime($hour,$min,$sec,$month,$day,0+$year); } /** * * Get the years, months, days, hours, minutes, and seconds of two times based on two times * @param String $start * @param String $end * @return ArrayObject */ private function diffDateTime($DateStart,$DateEnd){ $rs = array(); $sYear = substr($DateStart,0,4); $eYear = substr($DateEnd,0,4); $sMOnth= substr($DateStart,5,2); $eMOnth= substr($DateEnd,5,2); $sDay = substr($DateStart,8,2); $eDay = substr($DateEnd,8,2); $startTime = $this->fmDatetime($DateStart); $endTime = $this->fmDatetime($DateEnd); $dis = $endTime-$startTime;//Get the seconds of the two times $d = ceil($dis/(24*60*60));//Get the number of days $rs[‘day’] = $d;//Number of days $rs[‘hour’] = ceil($dis/(60*60));//hour $rs[‘minute’] = ceil($dis/60);//minute $rs[‘second’] = $dis;//Number of seconds $rs[‘week’] = ceil($d/7);//week $tem = ($eYear-$sYear)*12;//month $tem1 = $eYear-$sYear;//Year if($eMonth-$sMonth=0){ $tem++; $tem1++; } }else if($eMonth-$sMonth>0){//Subtract positive and negative months $tem1++; if($eDay-$sDay>=0){//And the date subtraction is a positive number $tem +=($eMonth-$sMonth)+1; }else{ $tem +=($eMonth-$sMonth); } } $rs[‘month’] = $tem; $rs[‘year’] = $tem1;…
PHP gets the year, month, day, hour, minute, and second during a specified time period-php tutorial
PHP gets the year, month, day, hour, minute, and second between the specified time period Requirement: The front end passes two standard time formats, the format is like 2009-05-12 12:12:30, and then as needed Returns the representation of different units for this time periodFor the verification of the time format, I have not posted the code here, so you can consider adding it when you use it Class Utils { /** * format MySQL DateTime (YYYY-MM-DD hh:mm:ss) Convert the data format found in mysql into time seconds * @param string $datetime */ public function fmDatetime($datetime ) { $year = substr($datetime,0,4); $mOnth= substr($datetime,5,2); $day = substr($datetime,8,2); $hour = substr($datetime,11 ,2); $min = substr($datetime,14,2); $sec = substr($datetime,17,2); return mktime($hour,$min,$sec,$month,$day,0+ $year); } /** * * Get the years, months, days, hours, minutes, seconds contained in two times based on two times * @param String $start * @param String $end * @return ArrayObject * / private function diffDateTime($DateStart,$DateEnd){ $rs = array(); $sYear = substr($DateStart,0,4); $eYear = substr($DateEnd,0,4); $sMOnth= substr( $DateStart,5,2); $eMOnth= substr($DateEnd,5,2); $sDay = substr($DateStart,8,2); $eDay = substr($DateEnd,8,2); $startTime = $this->fmDatetime($DateStart); $endTime = $this->fmDatetime($DateEnd); $dis = $endTime-$startTime;//Get the seconds of the two times $d = ceil($dis/( 24*60*60));//Get the number of days $rs[‘day’] = $d;//The…
PHP gets the year, month, day, hour, minute, and second during the specified time period
PHP gets the year, month, day, hour, minute, and second between the specified time period Requirement: The front end passes two standard time formats, the format is like 2009-05-12 12:12:30, and then returns the representation of different units of this time period as neededFor the verification of the time format, I have the code here It’s not posted, so I’ll consider adding it when I use it Class Utils { /** * format MySQL DateTime (YYYY-MM-DD hh:mm:ss) converts the data format found in mysql into time seconds * @param string $datetime */ public function fmDatetime($datetime) { $year = substr($datetime,0,4); $mOnth= substr($datetime,5,2); $day = substr($datetime,8,2); $hour = substr($datetime,11,2); $min = substr($datetime,14,2); $sec = substr($datetime,17,2); return mktime($hour,$min,$sec,$month,$day,0+$year); } /** * * Get the years, months, days, hours, minutes, and seconds of two times based on two times * @param String $start * @param String $end * @return ArrayObject */ private function diffDateTime($DateStart,$DateEnd){ $rs = array(); $sYear = substr($DateStart,0,4); $eYear = substr($DateEnd,0,4); $sMOnth= substr($DateStart,5,2); $eMOnth= substr($DateEnd,5,2); $sDay = substr($DateStart,8,2); $eDay = substr($DateEnd,8,2); $startTime = $this->fmDatetime($DateStart); $endTime = $this->fmDatetime($DateEnd); $dis = $endTime-$startTime;//Get the seconds of the two times $d = ceil($dis/(24*60*60));//Get the number of days $rs[‘day’] = $d;//Number of days $rs[‘hour’] = ceil($dis/(60*60));//hour $rs[‘minute’]…
PHP calculates the time difference between two dates (returns year, month, day)_PHP
In PHP programs, we often encounter processing time problems, such as: determining how long a user has been online, how many days they have been logged in, the time difference between two posts or log records between different operations, etc. In the article, a simple example is given of how to calculate the year, month, and day difference between two dates in PHP. strtotime($date2)) { $ymd = $date2; $date2 = $date1; $date1 = $ymd; } list($y1, $m1, $d1) = explode(‘-‘, $date1); list($y2, $m2, $d2) = explode(‘-‘, $date2); $y = $m = $d = $_m = 0; $math = ($y2 – $y1) * 12 + $m2 – $m1; $y = round($math / 12); $m = intval($math % 12); $d = (mktime(0, 0, 0, $m2, $d2, $y2) – mktime(0, 0, 0, $m2, $d1, $y2)) / 86400; if ($d <0) { $m -= 1; $d += date('j', mktime(0, 0, 0, $m2, 0, $y2)); } $m
PHP calculates the difference between two date times (returns year, month, day)_php instance
In PHP programs, you will often encounter processing time problems, such as: judging how long the user has been online, how many days have been logged in, the time difference between two posts, or log records between different operations, etc. In the article, a simple example of how to calculate the difference between two dates in PHP is year, month, and day. strtotime($date2)) { $ymd = $date2; $date2 = $date1; $date1 = $ymd; } list($y1, $m1, $d1) = explode(‘-‘, $date1); list($y2, $m2, $d2) = explode(‘-‘, $date2); $y = $m = $d = $_m = 0; $math = ($y2 – $y1) * 12 + $m2 – $m1; $y = round($math / 12); $m = intval($math % 12); $d = (mktime(0, 0, 0, $m2, $d2, $y2) – mktime(0, 0, 0, $m2, $d1, $y2)) / 86400; if ($d <0) { $m -= 1; $d += date('j', mktime(0, 0, 0, $m2, 0, $y2)); } $m
PHP calculates the difference between two date times (returns year, month, day)_php instance
In PHP programs, you will often encounter processing time problems, such as: judging how long the user has been online, how many days have been logged in, the time difference between two posts, or log records between different operations, etc. In the article, a simple example of how to calculate the difference between two dates in PHP is year, month, and day. strtotime($date2)) { $ymd = $date2; $date2 = $date1; $date1 = $ymd; } list($y1, $m1, $d1) = explode(‘-‘, $date1); list($y2, $m2, $d2) = explode(‘-‘, $date2); $y = $m = $d = $_m = 0; $math = ($y2 – $y1) * 12 + $m2 – $m1; $y = round($math / 12); $m = intval($math % 12); $d = (mktime(0, 0, 0, $m2, $d2, $y2) – mktime(0, 0, 0, $m2, $d1, $y2)) / 86400; if ($d <0) { $m -= 1; $d += date('j', mktime(0, 0, 0, $m2, 0, $y2)); } $m