How to Print Current Time in PHP
0 13024
Timestamp is the current time of an event that is recorded by a computer. A computer give accurate current time with minute and seconds. We use time() function to get current timestamp. Which gives us date and time.
<?php
$t=time();
echo "Timestamp is: ".time(). ' and date and time is : '.date("Y-m-d H:i:s A",$t);
echo '<br /><br />';
date_default_timezone_set("UTC");
$time = time();
echo "UTC Timestamp is: ". time(). ' and date and time is : '.date("Y-m-d H:i:s A",$time);
echo "<br /><br />";
date_default_timezone_set("Asia/Kuwait");
echo "Asia/ Kuwait Timestamp is: " .time(). ' and date and time is : '.date("Y-m-d H:i:s A",$t);
echo "<br /><br />";
?>
Result:
In this example we set time zone for 'Asia/ Kuwait and UTC.
If we have specified timezone than it save time stamp of that timezone. If we have not selected timezone than it depend server location. In our local-host, it can use default timezone mentioned in php.ini file.
Below are the format parameter of the date() function.
A: uppercase Ante meridiem and Post meridiem (AM or PM).
a: lowercase Ante meridiem and Post meridiem (am or pm).
Y: uppercase Y is defined year in four digits.
y: lowercase y is defined year in last two digit.
m: lowercase m is defined month (01-12).
M: uppercase M is defined month in textual format.
d: lowercase d is defined day of the month (01-31).
D: uppercase D is defined day in textual format.
H: uppercase H is defined hour with leading zeros for 24-hour (00-23),
h: lowercase h is hour with leading zeros for 12-hour (01-12).
i : lowercase i is minute with leading zeros (00-59).
s : lowercase s is seconds with leading zeros (00-59).
l : lowercase l is defined a day in full textual format.
L: uppercase L is defined a leap year.
Share:

Comments
Waiting for your comments