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
/d
Digit, 0,1,2 ... 9
a
am or pm
A
AM or PM
B
Swatch internet time
d
day with 2 digits, 01-31
D
3 character week day, e.g. Fri
F
Month name, e.g. January
g
12 hours, 1-12
G
24 hours, 0-23
h
12 hours, 01-12
H
24 hours, 00-23
i
minutes, 00-59
I
DST applied in current time zone or not, 1 is yes, 0 is no
j
day, 1-31
l
week day, e.g. Friday
L
leap year or not, 1 is yes, 0 is no
m
month, 01-12
M
month, e.g. Jan
n
month, 1-12
s
second,00-59
S
th, st, nd of such as 1st, 2nd, 4th
t
total days of a month, 28-31
T
current time zone of the server
U
seconds from 1970/01/01
w
week day, 0-6
Y
year by 4 digits
y
year by 2 digits
z
day of the year, 0-365
Z
time 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
?>




:: PHP Tutorials Home ::
PHP String Functions
 • concatenation • echo
 • ereg • ereg_replace
 • explode • htmlspecialchars
 • preg_match • preg_replace
 • preg_split • print,sprintf
 • str_replace • strcmp
 • strpos • strrev
 • strrpos • strtr
 • substr • substr_replace
PHP Array Functions
 • array_diff • array_flip
 • array_intersect • array_key_exists
 • array_keys • array_merge
 • array_pop • array_push
 • array_rand • array_search
 • array_splice • array_unshift
 • array_values • asort & arsort
 • count • in_array
 • ksort • shuffle
 • sort
PHP Data Types
 • array • associative array
 • date & time • number
 • class, object • regular expression
 • string • variables
PHP Loop & Conditions
 • continue & break • for loop
 • foreach • if else
 • not equal • while
PHP File System Functions
 • copy • delete, unlink
 • dirname • download url
 • file_exists • is_file
 • mkdir • read file
 • scandir • write file
PHP Popular Topics
 • ajax • clone
 • comments • constants
 • cookie • database
 • defined • die
 • form validation • gd, draw images
 • global variables • header url
 • heredoc • mail
 • pass by reference • print
 • regular expression • sessions
 • threads • xml parse
PHP Math Functions
 • abs • cos
 • exp • floor & ceil
 • fmod • log
 • max & min • pow
 • round • sin
 • sqrt • tan
endmemo.com © 2020  Terms of Use | Home