Timer.class.php
// ############### START INTRODUCE ############################ ###############
// Author: BlueMaple; Email: Bluemaple@x263.net
// Last modified time 2002-1-28 1:35
// This function is demand to resolve the return time display format problem. Including all formats of the DATE () function, the default $ TYPE is the most common type
In addition to $ Year, $ Month, $ Second; Add $ Week, $ ZONE (the first few days in the year), $ Nummonth (the number of days in the current month)
// The default is the most common format.
// Features, the most used in time processing is MKTIME, where MKTIME can be displayed in accordance with the habits (year, month, day)
// mktimey (); mktimew (); m ktimem (); mktimed (); convenient to set a time separated by y years, N month, convenient in mysql search
// subtime (); function can easily seek two times, the number of days, week, etc.
// ################ End Introduce ######################### #################
Class timer {
Var $ year; // year
Var $ MONTH; / / Month
Var $ day; // day
Var $ hour; //
Var $ minute; //
Var $ second; // second
Var $ week; // week
Var $ zone; // The first day of the year
Var $ Nummonth; // The number of days of the current month
Var $ mktime; // mktime
Function Year ($ TIME = ", $ TYPE = 0) {// Return Year
// $ TYPE = 0 means returning four years old
// $ TYPE = 1 indicates that the year is 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 means returning 1 ~ 12
// $ TYPE = 1 indicates that returns 01 ~ 12
// $ TYPE = 2 indicates returning Jan .. Three English letters
// $ TYPE = 3 means returning to English full name
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 Return 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) {// Return
// $ TYPE = 0 Return 1 ~ 24
// $ TYPE = 1 Return 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-> hours = Date ("g", $ time);
IF ($ TYPE == 3) $ this-> hours = Date ("g", $ time);
Return $ this-> Hour;
}
Function Minute ($ TIME = ", $ TY = 0) {// Return
IF ($ TIME == ") $ TIME = Time ();
IF ($ TYPE == 0) $ this-> minute = Date ("i", $ time);
Return $ this-> minute;
}
Function Second ($ TIME = ", $ TYPE = 0) {// Return Second
// $ TYPE = 0 Return 1 ~ 59
// $ TYPE = 1 Return word tail plus English order, 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 Return three letters of the week
// $ TYPE = 2 Return to the whole 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 = "") {// The first few days in the year;
IF ($ TIME == ") $ TIME = Time ();
$ this-> zone = Date ("z", $ time);
Return $ THIS-> ZONE
}
Function Nummonth ($ TIME = ") {// The current month
IF ($ TIME == ") $ TIME = Time ();
$ this-> Nummonth = Date ("t", $ TIME);
Return $ this-> Nummonth;
}
Function Time ($ TIME = ") {// acquisition all the 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 BetWeentime ($ atime = ", $ bTIME =" ") {/ / calculate two times separated days, month, etc.
IF ($ atime == ") $ atime = Time ();
IF ($ bTIME == "") $ bTIME = Time ();
}
Function Mktime ($ Year = 0, $ Month = 0, $ day = 0, $ hour = 0, $ minute = 0, $ second = 0) {// Annual monthly daytime
$ this-> mktime = mktime ($ HOUR, $ MINUTE, $ Second, $ MONTH, $ day, $ year);
Return $ this-> mktime;
}
Function Mktimey ($ TIME = ", $ y = 1) {// get a certain time Y year, the default 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) {// Get a certain time M month, default 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) {// get a time D days before, default 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) {// Get a certain time W Week, default is 1 week
$ this-> Time ($ time);
$ this-> mktime = mktime (0,0,0, $ this-> month, $ this-> day-7 * $ w, $ this-> year);
Return $ this-> mktime;
}
Function Subtime ($ atime = ", $ bTIME =" ") {// two time difference, the latter minus the former
IF ($ atime == ") $ atime = Time ();
IF ($ bTIME == "") $ bTIME = Time ();
$ subtime = $ bTIME - $ atime;
$ this-> second = intVal ($ subtime);
$ this-> minute = intVal ($ subtime / 60);
$ this-> hour = intVal ($ this-> minute / 60);
$ this-> day = intVal ($ this-> hours / 24);
$ this-> week = intVal ($ this-> day / 7);
$ this-> month = intVal ($ this-> day / 30);
$ this-> year = intVal ($ this-> monday / 12);
}
}
?>
Test text.php
Require ("./ Timer.class.php");
// ########################################
echo "
__________________________________
$ TIMER = New Timer;
$ D = $ TIMER-> mktimew ();
$ TIMER-> Subtime ($ d);
Echo "Second"; Echo $ TIMER-> Second; echo "
";
Echo "minute"; Echo $ TIMER-> Minute; echo "
";
Echo "Hour"; Echo $ TIMER-> Hour; Echo "
";
Echo "day"; echo $ TIMER-> day; echo "
";
Echo "Week"; Echo $ TIMER-> Week; Echo "
";
Echo "Month"; Echo $ TIMER-> MONTH; ECHO "
";
Echo "Year"; Echo $ TIMER-> Year; ECHO "
";
echo "
__________________________________
?>