You can use the PHP date() function to get the current date and time in various formats.
<?php $date = date('Y-m-d H:i:s a'); echo $date; ?>
Sample Output
2021-06-08 14:06:10 pm
The date and time returned above based on the server's default timezone that set in the server.
In PHP, You can set the default timezone using date_default_timezone_set() function.
The below program shows the date and time in India. Which is Asia/Kolkata
<?php date_default_timezone_set('Asia/Kolkata'); $date = date('Y-m-d H:i:s a'); echo $date; ?>
Sample Output
2021-06-08 11:42:07 am
0 0Please Login to Post the answer