Home > Article > Backend Development > How to get the current time in php
In PHP, the time() function can be used with the date() function to get what time it is currently. When the parameters of the date() function are set to "'h:i:s'", you can Get the current time, the syntax is "date('h:i:s', time());".
The operating environment of this article: Windows 10 system, PHP version 7.1, Dell G3 computer.
The time() function returns the number of seconds of the current time since the Unix epoch (January 1 1970 00:00:00 GMT).
The syntax is:
time();
Return value:
Returns an integer containing the Unix timestamp of the current time.
date() function is used to format time/date.
The date() function formats the timestamp into a more readable date and time.
Syntax
string date ( string $format [, int $timestamp ] )
Parameter Description
format Required. Specifies the format of the timestamp.
timestamp Optional. Specify timestamp. The default is the current date and time.
The example is as follows:
<?php echo date('h:i:s', time()); ?>
The output result is the current time
Recommended study:《 PHP video tutorial》
The above is the detailed content of How to get the current time in php. For more information, please follow other related articles on the PHP Chinese website!