PHP time full instance (very practical), _ PHP Tutorial

Source: Internet
Author: User
PHP time full instance (very practical ),. PHP time class complete instance (very practical), this article describes the PHP time class. Share it with you for your reference, the specific is as follows: phpheader (Content-type: texthtml; Charsetutf-8); full instance of the groovy PHP time class (very practical ),

This example describes the PHP time class. We will share this with you for your reference. The details are as follows:

<? Phpheader ("Content-type: text/html; Charset = utf-8"); class time {private $ year; // year private $ month; // month private $ day; // Daily private $ hour; // hour private $ minute; // minute private $ second; // second private $ microtime; // millisecond private $ weekday; // week private $ longDate; // The complete time format private $ diffTime; // The difference between the two times // returns the year time: the time format is timestamp 2013-3-27 function getyear ($ time = "", $ type = "") {if ($ time = "") {$ time = time ();} if ($ type = 1) {return $ this-> year = date ("y", $ time ); // returns the year 13} else {return $ this-> year = date ("Y", $ time ); // returns the four-digit year 2013 }}// returns the month time of the current time in the format of timestamp 2013-3-27 function getmonth ($ time = "", $ type = "") {if ($ time = "") {$ time = time ();} switch ($ type) {case 1: $ this-> month = date ("n ", $ time); // return Format 3 break; case 2: $ this-> month = date ("m", $ time); // return format 03 break; case 3: $ this-> month = date ("M", $ time); // return format: Mar break; case 4: $ this-> month = date ("F ", $ time); // return format: March break; default: $ this-> month = date ("n", $ time);} return $ this-> month ;} // returns the number of days of the current time in the format of timestamp 2013-3-4 function getday ($ time = "", $ type = "") {if ($ time = "") {$ time = time () ;}if ($ type = 1) {$ this-> day = date ("d", $ time ); // return format 04} else {$ this-> day = date ("j", $ time); // return format 4} 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 of 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 ($ t Ime);} return $ this-> longDate; }}?>

I hope this article will help you with PHP programming.

Articles you may be interested in:
  • Php implementation class instance for calculating execution time
  • Timer page runtime monitoring implemented by php
  • Php code used to calculate the program running time
  • PHP test program running time class
  • PHP performance optimization tool Benchmark class debugging execution time
  • Php code run time viewing class code sharing
  • PHP code for executing a page
  • PHP code for classifying and storing images by creation time

Compile (very practical), this article describes the PHP time class. Share it with you for your reference. The details are as follows: phpheader ("Content-type: text/html; Charset = utf-8"); linoleic...

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.