(Practical) PHP time full instance

Source: Internet
Author: User
This chapter describes (practical) details of a complete PHP time instance. For more information, see (Practical) PHP time full instance

 Year = date ("y", $ time); // returns the two year 16} else {return $ this-> year = date ("Y", $ time ); // returns the four-digit year 2016 }}// returns the month time of the current time. the time format is the timestamp 2016-8-27 function getmonth ($ time = "", $ type = "") {if ($ time = "") {$ time = time ();} switch ($ type) {case 1: $ this-> month = date ("n ", $ time); // return format 8 break; case 2: $ this-> month = date ("m", $ time); // return format 08 break; case 3: $ this-> month = date ("M", $ time); // The Returned format is Aug break; case 4: $ this-> month = date ("F ", $ time); // return format August break; default: $ this-> month = date ("n", $ time);} return $ this-> month ;} // returns the number of days of the current time. time format: timestamp 2016-8-29 function getday ($ time = "", $ type = "") {if ($ time = "") {$ time = time () ;}if ($ type = 1) {$ this-> day = date ("d", $ time ); // return format 29} else {$ this-> day = date ("j", $ time); // return format 29} return $ this-> day ;} // returns the hour of the current time 1:19:21 function gethour ($ time = "", $ type = "") {if ($ time = "") {$ time = time () ;}switch ($ type) {case 1: $ this-> hour = date ("H", $ time); // format: 1 20 break; case 2: $ this-> hour = date ("h", $ time); // format 01 08 break; case 3: $ this-> hour = date ("G", $ time); // format 1 20 break; case 4: $ this-> hour = date ("g ", $ time); // format 1 8 break; default: $ this-> hour = date ("H", $ time);} return $ this-> hour ;} // returns the minutes of the current time function getminute ($ time = "", $ type = "") {if ($ time = "") {$ time = time () ;}$ this-> minute = date ("I", $ time); // format 09 return $ this-> minute ;} // returns the current time in seconds 20:19:01 function getsecond ($ time = "", $ type = "") {if ($ time = "") {$ time = time () ;}$ this-> second = date ("s", $ time); // format 01 return $ this-> second ;} // return the number of weeks of the current time function getweekday ($ time = "", $ type = "") {if ($ time = "") {$ time = time () ;}if ($ type = 1) {$ this-> weekday = date ("D", $ time ); // format: Sun} else if ($ type = 2) {$ this-> weekday = date ("l", $ time ); // format Sunday} else {$ this-> weekday = date ("w", $ time); // format number to represent 0--6} return $ this-> weekday ;} // compare the two time formats: function compare ($ time1, $ time2) {$ time1 = strtotime ($ time1); $ time2 = strtotime ($ time2 ); if ($ time1 >=$ time2) {// if the first time is greater than or equal to the second time, return 1; otherwise, return 0 return 1;} else {return-1 ;}} // compare the difference between two time functions diffdate ($ time1 = "", $ time2 = "") {// echo $ time1 .'------'. $ time2 .'
'; If ($ time1 = "") {$ time1 = date ("Y-m-d H: I: s ");} if ($ time2 = "") {$ time2 = date ("Y-m-d H: I: s") ;}$ date1 = strtotime ($ time1 ); $ date2 = strtotime ($ time2); if ($ date1> $ date2) {$ diff = $ date1-$ date2;} else {$ diff = $ date2-$ date1 ;} if ($ diff> = 0) {$ day = floor ($ diff/86400); $ hour = floor ($ diff % 86400)/3600 ); $ minute = floor ($ diff % 3600)/60); $ second = floor ($ diff % 60); $ this-> diffTime = 'difftime '. $ day. 'Day '. $ hour. 'Hourly '. $ minute. 'Min' . $ Second. 'second';} return $ this-> diffTime;} // returns the function buildDate ($ time = "", $ type = "") of month X, year X "") {if ($ type = 1) {$ this-> longDate = $ this-> getyear ($ time ). 'year '. $ this-> getmonth ($ time ). 'month '. $ this-> getday ($ time ). 'day';} else {$ this-> longDate = $ this-> getyear ($ time ). 'year '. $ this-> getmonth ($ time ). 'month '. $ this-> getday ($ time ). 'Day '. $ this-> gethour ($ time ). ':'. $ this-> getminute ($ time ). ':'. $ this-> getsecond ($ Time) ;}return $ this-> longDate ;}}?>

The above is the content of a complete PHP time instance. For more information, see PHP Chinese network (www.php1.cn )!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.