How to get Current Time & Date using PHP?

How to Expose and Route to a Resource?
How to Expose and Route to a Resource?

Problem:- How to get Current Time & Date using PHP?

Solution – Get Current Time & Date using PHP

Method 1

<?php
echo date('r');
//output like Sun, 16 Dec 2018 03:54:05 +0000 (Based on server time)
?>

Method 2

<?php
$when = new DateTime();
echo $when->format('r');
// same output as above code Sun, 16 Dec 2018 03:56:37 +0000 
?>

Method 3

<?php
$now1 = getdate(); // return a array
$now2 = localtime(); // return a array
echo "{$now1['hours']}:{$now1['minutes']}:{$now1['seconds']}";
echo "<br>";
echo "{$now2['2']}:{$now2['1']}:{$now2['0']}";
?>

इसे भी पढ़े – Kruti Dev 11 अपने PC में कैसे Install करें?

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *