How to get current date and time in php

How to get current date and time in php ?
You can simply use date function to get current date in php as below :


$date = date('Y-m-d H:i:s');

This would return the the current date in format of $date = ‘2015-05-06 16:30:01’.

In php 5.2.0 you can also use this method to get current date and time in php.

$date = new DateTime();
$currDate = $date->format('Y-m-d H:i:s');

This would also return the the current date in format of $currDate = ‘2015-05-06 16:30:01’.

For Setting Default timezone in php you can refer this article :
http://tutorialsplane.com/set-default-timezone-in-php/


Advertisements

Add Comment

📖 Read More