Home  >  Article  >  Backend Development  >  How to get the current time in php

How to get the current time in php

WBOY
WBOYOriginal
2022-02-22 13:47:252339browse

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());".

How to get the current time in php

The operating environment of this article: Windows 10 system, PHP version 7.1, Dell G3 computer.

How to get the current time in php

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(&#39;h:i:s&#39;, time()); 
?>

The output result is the current time

How to get the current time in php

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn