If you want to know current date and time using PHP, you can use date() function to get current date and time in any PHP version. You can also find the Date Time PHP class in PHP> 5.2.
In this article I will show how to get current date and time with PHP.
Print Date and Time
To print the current date and time use date() function. It provides the information using php.ini configuration.
<?php echo date('Y-m-d H:i:s'); ?>
Print the current date time using DateTime() class. It will also use the default timezone.
<?php $datetime = new DateTime(); echo $datetime->format('Y-m-d H:i:s'); ?>
Print Date and Time with Timezone
If your data has been stored in UTC timezone (2018-01-12 01:17:23) in your database. You can convert its date time to EST timezone.
<?php $date = new DateTime('2011-11-10 20:17:23', new DateTimeZone('UTC')); $date->setTimezone(new DateTimeZone('EST')); echo $date->format('Y-m-d H:i:s'); ?>
Now you will get below result after executing above command.
2018-01-12 01:17:23
If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website www.looklinux.com. To become an author at LookLinux Submit Article. Stay connected to Facebook.
Leave a Comment