Home > Backend Development > PHP Tutorial > time function in php

time function in php

不言
Release: 2023-03-24 16:58:01
Original
4221 people have browsed it

The content introduced in this article is about the time function in php, which has certain reference value. Now I share it with everyone. Friends in need can refer to it

Time function
Time and date
Timestamp
1. It is an integer
2. From January 1, 1970 to the current integer (calculated starting from 0:00:00 on January 1, 1970 Greenwich (London, England) time)
Why use timestamp, in order to facilitate calculation
Commonly used time functions
time() Get the current timestamp
date(' Format', 'timestamp') is used to perform some calculations and can know some current time information
Note: If the timestamp is not provided, it means the current timestamp
The meaning of symbols in the format
Y Year
m Month
d Date
H Hours
i Minutes
s Seconds
Time zone
php is a universal language. The default time zone is 0, London time zone, UK. China, the eight east districts, the eight time zones east of London
How to change the time zone
1. Modify the configuration file
Configuration file date.timezone=corresponding time zone
asia/shanghai
PRC China
Etc/GMT-8
The current time zone is 8 hours ahead of the standard time zone, that is, the current time zone minus 8 hours equals Greenwich Time
2. Use function settings
date_default_timezone_set ('PRC') Set the time zone
date_default_timezone_get() get the time zone
Note: No matter what the time zone is, your timestamp will not change, the setting will only be lost It just sets the displayed time
Other functions
mktime (hour, minute, second, month, day, year)
strtotime() parses any English text datetime description into a unix timestamp
strtotime('1 day') 1 day
1 week 1 week
1 week 2 days 4 hours 2seconds
Time and date
Time stamp
1. It is an integer
2 , from January 1, 1970 to the current integer (calculated starting from 0:00:00 on January 1, 1970, Greenwich (London, England) time)
Why use time Stamp, in order to facilitate calculation
Commonly used time functions
time() Get the current timestamp
date('format','timestamp') Use To do some calculations, you can know some current time information
Note: If the timestamp is not provided, it means the current timestamp
The meaning of the symbols in the format
Y Year
m Month
d Date
H Hour
i Minutes
s Seconds
Time Zone
php is a worldwide language. The default time zone is 0, London time zone, UK. China, the eight east districts, the eight time zones east of London
How to change the time zone
1. Modify the configuration file
Configuration file date.timezone=corresponding time zone
asia/shanghai
PRC China
Etc/GMT-8
The current time zone is 8 hours ahead of the standard time zone, which means the current time zone minus 8 hours equals Greenwich Time
2. Use function settings
date_default_timezone_set('PRC') Set the time zone
date_default_timezone_get() Get the time zone
Note: No matter what the time zone is, your timestamp will not Change, the setting is lost only to set the displayed time
Other functions
mktime (hour, minute, second, month, day, year)
strtotime() parses any English text datetime description into a unix timestamp
strtotime(' 1 day') 1 day
1 week 1 week
1 week 2 days 4 hours 2seconds

Related recommendations:

PHP time conversion remaining time

Detailed explanation of PHP timestamp function

The above is the detailed content of time function in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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