In this tutorial, we are going to see how to get the current date and time in PHP. You can use PHP’s date() function to get the current date and time in different formats, for example,
date('d/m/y H:i:s'), etc.
How to get the current date and time in PHP
<?php $date = date('d-m-y h:i:s'); echo $date; ?>
The date and time returned by the example above are based on the server’s default time zone setting. If you want to display the date and time according to the user’s time zone, you can set it manually using the date_default_timezone_set() function before calling the date() function.
The following example displays date and time in America, in the time zone corresponding to America/Los_Angeles.
<?php // Define the new time zone date_default_timezone_set('America/Los_Angeles'); $date = date('d-m-y h:i:s'); echo $date; ?>
09-07-19 08:24:38MCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More