Posts
Showing posts from April, 2017
How to Display Date in PHP
- Get link
- X
- Other Apps
To get current datetime (now) with PHP you can use date with any PHP version, or better datetime class with PHP >= 5.2 Various date format expressions are available here . Example using date This expression will return NOW in format Y-m-d H:i:s 1 2 3 <?php echo date ( 'Y-m-d H:i:s' ); ?> Example using datetime class This expression will return NOW in format Y-m-d H:i:s 1 2 3 4 <?php $dt = new DateTime(); echo $dt ->format( 'Y-m-d H:i:s' ); ?> A more complete approach Above examples will return NOW using your server timezone, as it is defined in php.ini , for example: 1 2 3 4 [Date] ; Defines the default timezone used by the date functions ; http://php.net/date.timezone date.timezone = Europe/Athens But, the best approach is to save dates to UTC . UTC (also called Zulu time) is the standard in...