How to get the current time in php

WBOY
Release: 2023-03-15 13:08:02
Original
2332 people have browsed it

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();
Copy after login

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 ] )
Copy after login

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()); 
?>
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!