For the original processing time class, please correct me
Source: Internet
Author: User
Timer. class. php? // ####################### StartIntroduce ############### #########################// author: bluemaple; email: bluemaple@x263.net // last modified at 2002-1-281: 35 // This timer. class. php
// ####################### Start Introduce ############## #########################
// Author: bluemaple; email: bluemaple@x263.net
// Last Modification time:
// This function solves the problem of returned Time display format. Including all formats of the date () function. the default $ type is the most common type.
// Except for $ year, $ month, $ day, $ hour, $ minute, $ second; added $ week (week), $ zone (day of the year ), $ numMonth (number of days in the current month)
// The default format is the most common format.
// Features. mktime is the most used in time processing. mktime can be set here as expected (year, month, or day ).
// MktimeY (); mktimeW (); mktimeM (); mktimeD (); you can easily set a time interval between y and n months, which is convenient to use in mysql search.
// SubTime (); the function can be used to conveniently find the days and weeks of two time differences.
// ######################## End Introduce ############# ###########################
Class TIMER {
Var $ year; // year
Var $ month; // month
Var $ day; // day
Var $ hour; // hour
Var $ minute; // minute
Var $ second; // second
Var $ week; // week
Var $ zone; // The Day of the year
Var $ numMonth; // Number of days in the current month
Var $ mktime; // mktime
Function year ($ time = "", $ type = 0) {// return year
// $ Type = 0 indicates the year in which four digits are returned.
// $ Type = 1 indicates the year in which two digits are returned.
If ($ time = "") $ time = time ();
If ($ type = 0) $ this-> year = date ("Y", $ time );
If ($ type = 1) $ this-> year = date ("y", $ time );
Return $ this-> year;
}
Function month ($ time = "", $ type = 0) {// return month
// $ Type = 0 indicates that 1 ~ is returned ~ 12
// $ Type = 1 indicates 01 ~ is returned ~ 12
// $ Type = 2 indicates that three English letters (jan) are returned.
// $ Type = 3 indicates that the full English name is returned.
If ($ time = "") $ time = time ();
If ($ type = 0) $ this-> month = date ("n", $ time );
If ($ type = 1) $ this-> month = date ("m", $ time );
If ($ type = 2) $ this-> month = date ("M", $ time );
If ($ type = 3) $ this-> month = date ("F", $ time );
Return $ this-> month;
}
Function day ($ time = "", $ type = 0) {// Return day
// $ Type = 0 returns 1 ~ 31
// $ Type = 1 returns 01 ~ 31
If ($ time = "") $ time = time ();
If ($ type = 0) $ this-> day = date ("j", $ time );
If ($ type = 1) $ this-> day = date ("d", $ time );
Return $ this-> day;
}
Function hour ($ time = "", $ type = 0) {// when return
// $ Type = 0 returns 1 ~ 24
// $ Type = 1 returns 1 ~ 12
// $ Type = 2 return 01 ~ 24
// $ Type = 3 return 01 ~ 12
If ($ time = "") $ time = time ();
If ($ type = 0) $ this-> hour = date ("H", $ time );
If ($ type = 1) $ this-> hour = date ("h", $ time );
If ($ type = 2) $ this-> hour = date ("G", $ time );
If ($ type = 3) $ this-> hour = date ("g", $ time );
Return $ this-> hour;
}
Function minute ($ time = "", $ type = 0) {// return score
If ($ time = "") $ time = time ();
If ($ type = 0) $ this-> minute = date ("I", $ time );
Return $ this-> minute;
}
Function second ($ time = "", $ type = 0) {// return second
// $ Type = 0 returns 1 ~ 59
// $ Type = 1 returns the suffix of the character plus the English sequence, two English letters
If ($ time = "") $ time = time ();
If ($ type = 0) $ this-> second = date ("s", $ time );
If ($ type = 1) $ this-> second = date ("S", $ time );
Return $ this-> second;
}
Function week ($ time = "", $ type = 0) {// return week
// $ Type = 0 returns 0 ~ 6
// $ Type = 1 returns the week with three letters
// $ Type = 2 returns the week of the full letter
If ($ time = "") $ time = time ();
If ($ type = 0) $ this-> week = date ("w", $ time );
If ($ type = 1) $ this-> week = date ("D", $ time );
If ($ type = 2) $ this-> week = date ("l", $ time );
Return $ this-> week;
}
Function zone ($ time = "") {// day of the year;
If ($ time = "") $ time = time ();
$ This-> zone = date ("z", $ time );
Return $ this-> zone;
}
Function numMonth ($ time = "") {// Number of days in the current month
If ($ time = "") $ time = time ();
$ This-> numMonth = date ("t", $ time );
Return $ this-> numMonth;
}
Function time ($ time = "") {// Obtain all parameters about the current time.
If ($ time = "") $ time = time ();
$ This-> year ($ time );
$ This-> month ($ time );
$ This-> day ($ time );
$ This-> hour ($ time );
$ This-> minute ($ time );
$ This-> second ($ time );
$ This-> week ($ time );
$ This-> zone ($ time );
$ This-> numMonth ($ time );
}
Function mktime ($ year = 0, $ month = 0, $ day = 0, $ hour = 0, $ minute = 0, $ second = 0) {// year, month, day, hour, minute, second
$ This-> mktime = mktime ($ hour, $ minute, $ second, $ month, $ day, $ year );
Return $ this-> mktime;
}
Function mktimeY ($ time = "", $ y = 1) {// Obtain one year before y. The default value is 1.
$ This-> time ($ time );
$ This-> mktime = mktime (0, 0, 0, $ this-> month, $ this-> day, ($ this-> year-$ y ));
Return $ this-> mktime;
}
Function mktimeM ($ time = "", $ m = 1) {// Obtain a time before m months. The default value is 1.
$ This-> time ($ time );
$ This-> mktime = mktime (0, 0, 0, $ this-> month-$ m, $ this-> day, $ this-> year );
Return $ this-> mktime;
}
Function mktimeD ($ time = "", $ d = 1) {// Obtain a time before d days. the default value is 1 day.
$ This-> time ($ time );
$ This-> mktime = mktime (0, 0, 0, $ this-> month, $ this-> day-$ d, $ this-> year );
Return $ this-> mktime;
}
Function mktimeW ($ time = "", $ w = 1) {// Obtain a time before w weeks. The default value is 1 week.
$ This-> time ($ time );
$ This-> mktime = mktime (0, 0, 0, $ this-> month, $ this-> day-7 * $ w, $ this-> year );
Return $ this-> mktime;
}
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.