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

How to determine the current time in php

青灯夜游
青灯夜游Original
2022-02-15 14:37:093729browse

How to determine what time it is in php: 1. Use the time() or strtotime() function to get the timestamp representing the current time; 2. Use "date("H:i:s", time Stamp)" statement formats the timestamp, converts it into "hour:minute:second" format and outputs it.

How to determine the current time in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

php determines the current What are the points

#1. Get the timestamp representing the current time

Method 1: Use the time() function

time () function returns the current time in seconds since the Unix epoch (January 1 1970 00:00:00 GMT).

Syntax:

time()

Method 2: strtotime() function

strtotime() function parses any string datetime description into a Unix timestamp (since January 1 1970 seconds since 00:00:00 GMT).

Syntax:

strtotime("now")

2. Use date() function to format timestamp

date("H:i:s",时间戳)

Full code:

<?php
header("Content-type:text/html;charset=utf-8");
ini_set(&#39;date.timezone&#39;, &#39;Asia/Shanghai&#39;);//设置时区
$time=time();
echo "当前是:".date("H:i:s",$time);
?>

How to determine the current time in php

Extended knowledge:

The world is divided into 24 time zones. Each time zone has its own local time. The local time of each time zone differs by 1 at the same time. ~23 hours, for example, the difference between local time in London, UK and local time in Beijing is 8 hours. To set the time zone, please refer to the article "How to convert time zone time in php?"

Recommended learning:《PHP Video Tutorial

The above is the detailed content of How to determine 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