How Print Current Time in PHP | Print Run Time | PHP Code
×


How to Print Current Time in PHP

8029

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).

 : lowercase i is minute with leading zeros (00-59).

: lowercase s is seconds with leading zeros (00-59).

: lowercase l is defined a day in full textual format.

L: uppercase L is defined a leap year.




Best WordPress Hosting


Share:


Discount Coupons

Get a .COM for just $6.98

Secure Domain for a Mini Price



Leave a Reply


Comments
    Waiting for your comments