Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the PHP timestamp strtotime () function

Shulou Source: shulou.com Published: 2022-06-03 07:40:05 10月01日 Update

This article introduces the knowledge of "how to use the PHP timestamp strtotime () function". In the operation of actual cases, many people will encounter this dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Gets the specified year, month and day converted to a timestamp:

The pHP timestamp function gets the unix timestamp strtotime of the specified date ('2012-12-7')

Examples are as follows:

The copy code is as follows:

Description: returns the 00:00:00 timestamp on December 7, 2012.

Convert the current year, month and day into a timestamp: the PHP timestamp function gets the unix timestamp of the current date

Examples are as follows:

The copy code is as follows:

Ming: returns the timestamp of the current time, year, month, day, hour and second.

Convert the timestamp to the year, month and day:

The copy code is as follows:

Example

The copy code is as follows:

PHP timestamp function to get the date and time of English text

For easy comparison, use date to convert the current timestamp and the specified timestamp into system time

(1) print the timestamp strtotime ("+ 1 day") at this time tomorrow

Current time: echo date ("Y-m-d H:i:s", time ()) result: 2009-01-22 09:40:25

Specified time: echo date ("Y-m-d H:i:s", strtotime ("+ 1 day")) result: 2009-01-23 09:40:25

(2) print the timestamp strtotime ("- 1 day") of this time yesterday.

Current time: echo date ("Y-m-d H:i:s", time ()) result: 2009-01-22 09:40:25

Specified time: echo date ("Y-m-d H:i:s", strtotime ("- 1 day")) result: 2009-01-21 09:40:25

(3) print the timestamp strtotime ("+ 1 week") at this time next week.

Current time: echo date ("Y-m-d H:i:s", time ()) result: 2009-01-22 09:40:25

Specified time: echo date ("Y-m-d H:i:s", strtotime ("+ 1 week")) result: 2009-01-29 09:40:25

(4) print the timestamp strtotime ("- 1 week") at this time last week.

Current time: echo date ("Y-m-d H:i:s", time ()) result: 2009-01-22 09:40:25

Specified time: echo date ("Y-m-d H:i:s", strtotime ("- 1 week")) result: 2009-01-15 09:40:25

(5) print the timestamp strtotime ("next Thursday") that specifies the day of next week.

Current time: echo date ("Y-m-d H:i:s", time ()) result: 2009-01-22 09:40:25

Specified time: echo date ("Y-m-d H:i:s", strtotime ("next Thursday")) result: 2009-01-29 00:00:00

(6) print the timestamp strtotime ("last Thursday") that specifies the day of the previous week.

Current time: echo date ("Y-m-d H:i:s", time ()) result: 2009-01-22 09:40:25

Specified time: echo date ("Y-m-d H:i:s", strtotime ("last Thursday")) result: 2009-01-15 00:00:00

That's all for "how to use the PHP timestamp strtotime () function". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Time result code function year month day date content week more knowledge examples practicality achievement next dilemma reality situation text article Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn MySQL Shulou Technology Redmi Huawei