PHP Date & Times


PHP date() function returns current or specified date and time. Before use date(), the default time zone must be set by date_default_timezone_set().

<?PHP
date_default_timezone_set("America/New_York");
$d=date("Y/m/d");
echo $d; //2000/09/06
?>

string date(string format[, int timestamp]), if the 2nd parameter is not specified, the returned time is current time. The complete list of date format:
Format Definition
aam or pm
AAM or PM
BSwatch internet time
dday with 2 digits, 01-31
D3 character week day, e.g. Fri
FMonth name, e.g. January
g12 hours, 1-12
G24 hours, 0-23
h12 hours, 01-12
H24 hours, 00-23
iminutes, 00-59
IDST applied in current time zone or not, 1 is yes, 0 is no
jday, 1-31
lweek day, e.g. Friday
Lleap year or not, 1 is yes, 0 is no
mmonth, 01-12
Mmonth, e.g. Jan
nmonth, 1-12
ssecond,00-59
Sth, st, nd of such as 1st, 2nd, 4th
ttotal days of a month, 28-31
Tcurrent time zone of the server
Useconds from 1970/01/01
wweek day, 0-6
Yyear by 4 digits
yyear by 2 digits
zday of the year, 0-365
Ztime zone offset by seconds, ~43200 - 43200

time() function returns the seconds from 01/01/1970 00:00:00 GMT.
microtime() function returns the seconds and microsends from 01/01/1970 00:00:00 GMT.
<?PHP
echo time();  //1300050832
echo microtime();  //0.41567500 1300050898
?>

getdate() function returns an array of current or specified time information.
<?PHP
date_default_timezone_set("America/New_York");
$arr = getdate(1000050898);
print_r($arr);
//Array ( [seconds] => 58 [minutes] => 54 [hours] => 11 [mday] => 9 [wday] => 0 [mon] => 9 [year] => 2001 [yday] => 251 [weekday] => Sunday [month] => September [0] => 1000050898 ) 0//echo microtime();  //0.41567500 1300050898
echo $arr["wday"]; //0
?>