search
HomeBackend DevelopmentPHP TutorialDetailed introduction to PHP strtotime function

This article introduces the usage of the timestamp function strtotime() in PHP. Friends in need can refer to it.

The strtotime function is a very good function. Using it flexibly will bring a lot of convenience to your work. However, the PHP manual does not introduce much about the parameters of this function, and there is no introduction to other functions. very few. First read the manual introduction: strtotime — Parse any English text datetime description into a Unix timestamp Format: int strtotime ( string $time [, int $now ] ) This function expects a string containing a date in US English format and attempts to parse it into a Unix timestamp (number of seconds since January 1 1970 00:00:00 GMT) relative to the time given by the now parameter, If this parameter is not provided, the current system time is used.

 This function will use the TZ environment variable (if any) to calculate the timestamp. Since PHP 5.1.0 there is an easier way to define the time zone used in all date/time functions. This process is documented on the date_default_timezone_get() function page. Note: If the given year is in two-digit format, the values ​​0-69 represent 2000-2069 and 70-100 represent 1970-2000.

Parameters time The parsed string, formatted according to the GNU ? Date Input Format syntax. Before PHP 5.0, milliseconds were not allowed in time. Since PHP 5.0, they are allowed but will be ignored. now The timestamp used to calculate the return value. The default value of this parameter is the current time time(), and it can also be set to a timestamp of other times (a feature I have always ignored, ashamed) Return value: Returns the timestamp if successful, otherwise returns FALSE. Before PHP 5.1.0, this function returned -1 on failure, and later versions returned false.

The first parameter of strtotime can be our common English time format, such as "2008-8-20" or "10 September 2000" and so on. It can also be a time description based on the parameter now, such as "+1 day" and so on.

The following is a list of available parameters for the latter method, where "current time" refers to the value of the second parameter now of strtotime, which defaults to the current time. 1. List of English names and commonly used abbreviations of months, Japanese and Japanese: january,february,march,april,may,june,july,august,september,sept,october,november,december, sunday,monday,tuesday,tues,wednesday,wednes,thursday,thur,thurs,friday,saturday

2. Time parameters and detailed description: am: the time is before noon morning pm: the time is noon or later afternoon year: one year; for example, “next year” month : one month; for example, “last month” month, such as “last month” represents the previous month fortnight: two weeks; for example, “a fortnight ago” Two weeks, for example, “a fortnight ago” means two weeks ago week: one week day: a day day hour: an hour minute: a minute min : same as minute Same as “minute” second : a second second sec: same as second Same as "second"

3. Related and sequential instructions: +n/-n: Calculate the current time, plus or minus the specified time. For example, "+1 hour" means the current time plus one hour. ago :time relative to now; such as “24 hours ago” tomorrow: 24 hours later than the current date and time. Based on the current time (including date and time), the same time tomorrow yesterday: 24 hours earlier than the current date and time. Based on the current time (including date and time), the same time yesterday today: the current date and time Current time (including date and time) now: the current date and time Current time (including date and time) last : modifier meaning “the preceding”; for example, “last tuesday” represents “the previous one”, such as “last tuesday” represents “the same time last Tuesday” this : the given time during the current day or the next occurrence of the given time; for example, “this 7am” gives the timestamp for 07:00 on the current day, while “this week” gives the timestamp for one week from the current time: The specified time of the day or the timestamp of the following time period. For example, "this 7am" gives the timestamp of 7:00 that day, and "this week" gives the timestamp of the entire week starting from the current time. , which is the current time (tested by me: strtotime('this week')=strtotime('now')); next : modifier meaning the current time value of the subject plus one; for example, “next hour” The current time plus the specified time, for example, “next hour” means the current time plus one hour, that is, plus 3600

//I came here first, so I haven’t translated it yet first : ordinal modifier, esp. for months; for example, “May first” (actually, it's just the same as next) third : see first (note that there is no “second” for ordinality, since that would conflict with the second time value) fourth : see first fifth : see first sixth : see first seventh: see first eighth : see first ninth: see first tenth : see first eleventh : see first twelfth : see first

4.时区描述: gmt : Greenwich Mean Time ut : Coordinated Universal Time utc : same as ut wet : Western European Time bst : British Summer Time wat : West Africa Time at : Azores Time ast : Atlantic Standard Time adt : Atlantic Daylight Time est : Eastern Standard Time edt : Eastern Daylight Time cst : Central Standard Time cdt : Central Daylight Time mst : Mountain Standard Time mdt : Mountain Daylight Time pst : Pacific Standard Time pdt : Pacific Daylight Time yst : Yukon Standard Time ydt : Yukon Daylight Time hst : Hawaii Standard Time hdt : Hawaii Daylight Time cat : Central Alaska Time akst : Alaska Standard Time akdt : Alaska Daylight Time ahst : Alaska-Hawaii Standard Time nt : Nome Time idlw : International Date Line West cet : Central European Time met : Middle European Time mewt : Middle European Winter Time mest : Middle European Summer Time mesz : Middle European Summer Time swt : Swedish Winter Time sst : Swedish Summer Time fwt : French Winter Time fst : French Summer Time eet : Eastern Europe Time, USSR Zone 1 bt : Baghdad Time, USSR Zone 2 zp4 : USSR Zone 3 zp5 : USSR Zone 4 zp6 : USSR Zone 5 wast : West Australian Standard Time wadt : West Australian Daylight Time cct : China Coast Time, USSR Zone 7 jst : Japan Standard Time, USSR Zone 8 east : Eastern Australian Standard Time eadt : Eastern Australian Daylight Time gst : Guam Standard Time, USSR Zone 9 nzt : New Zealand Time nzst : New Zealand Standard Time nzdt : New Zealand Daylight Time idle : International Date Line East

附,具体应用举例。 参见文章:php strtotime()函数用法举例



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
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool