Time and Date function in Php


Time and Date function is used to display date and time in your webpage or to check the last view of the user.

Syntax for using Time and Date function

date_default_timezone_set("your time zone");
date('d-m-y h:i:s A');

Example :-
<!DOCTYPE html>
<html>
<head><title>expertcodingmaster.com</title>
</head>
<body>
<?php
/* below are the example of different format to display Date and Time which can be used according to your requirement  */ 
date_default_timezone_set("Asia/Kolkata");    // set your own time zone 
echo date('d-m-y h:i:s a') . "<br>";
echo date('D-M-Y h:i:s A') . "<br>";
echo date('D-M-Y H:i:s A') . "<br>";
echo date('D-M-Y h:I:s A') . "<br>";
echo date('D-M-Y h:i:S A') . "<br>";
echo date('D-M-Y h:i:s A') . "<br>";
echo  date('d-m-y') . "<br>";
echo  date('h:i:s a') . "<br>";
?>
</body>
</html>

Output of the above code
31-01-17 12:16:27 am

Tue-Jan-2017 12:16:27 AM


Tue-Jan-2017 00:16:27 AM


Tue-Jan-2017 12:0:27 AM


Tue-Jan-2017 12:16:st AM


Tue-Jan-2017 12:16:27 AM


31-01-17


12:16:27 am




No comments: