How to get Current Time & Date using PHP?

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']}";
?>

 

Be the first to comment

Leave a Reply

Your email address will not be published.


*