If the time format is absolute time, the now parameter does not work. If the time format is relative time, the relative time is provided by now, or if the now parameter is not provided, the current time is used. -1 is returned if the request
In PHP we use the
strotime () functionYou can resolve the date and time of any English text to a Unix timestamp. Its syntax is as follows:
Strotime () function syntax format
Strtotime (Time,now);
Its value is relative to the time given by the
If the format of time is absolute, then the now parameter does not work. If the format of time is relative, its relative time is provided by now, or if it is not supplied with the current time. Returns-1 on failure.
Echo Strtotime ("Now"), "\
PHP. ini needs to be configured for a higher PHP version.
Solution
1: Change PHP. ini
[Date]
; Defines the default timezone used by the date functions
Http://php.net/date.timezone
Date. timezone = 'Asia/Shanghai'
2: Write in program code
If the time format is absolute time, the now parameter does not work. If the time format is relative time, the relative time is provided by now, or if the now parameter is not provided, the current time is used. -1 is returned if the request fails.
The now parameter does not work if the time is in absolute times format. If time is in a relative time format, it is provided by now, or the current time is not available if the?? Returns-1 when failed.
Echo Strtotime ("Now"), "\ n";
Echo
Implement functionsObtain and compare the half time with the time specified by the user, and then determine that the operation is performed within a few days.Program code The code is as follows:Copy code $ D = '2017-01-09 ';$ Time = time ();$
1. Obtain the unix timestamp of the specified dateStrtotime ("2009-1-22") example:1. echo strtotime ("2009-1-22 ")Result: 1232553600Returns the January 22, 2009 00:00:00 timestamp.2. Obtain the date and time of the English textExample:For ease of
SyntaxStrtotime (time, now) parameter descriptionTime specifies the time string to be parsed.Now is used to calculate the timestamp of the returned value. If this parameter is omitted, the current time is used.Example The code is as follows:Copy
One, gets the UNIX timestamp for the specified date
Strtotime ("2009-1-22") examples are as follows:
1.echo strtotime ("2009-1-22")
Results: 1232553600Description: Return January 22, 2009 0:0 0 seconds timestampSecond, get the English text date
Var_dump (Strtotime (' 1441185010 '));//output bool (FALSE) Var_dump (Strtotime (' 1451382400 '));//output int (13591003898)
It's strange, why are the two results different?
Reply to discussion (solution)
I PHP5.6 return two false, what
This function uses the TZ environment variable (if any) to calculate the timestamp. PHP 5.1.0 has an easier way to determine the time zone of All/dateTime functions used. This process is explained on the page of the date_default_timezone_get ()
This article illustrates the use of Strtotime functions in PHP. Share to everyone for your reference. Specifically as follows:
Strtotime (String $ time [, int $ now]) int strtotime (string $time [, int $now] The function expects a date format
Strtotime can parse the date-time description of any English text into a Unix timestamp, we use the mktime () or date () format date time to get the specified timestamp to achieve the required DateTime.
implementation function : Gets the timestamp
Previously, we used the strtotime () function to compare the size of two dates. apart from comparing the size of two dates, PHP can also accurately calculate the difference between two dates. In this chapter, we still use the strtotime () function
PHP calculates the first and last days of a month. To count the first and last days of a month in php, we can use the strtotime function for conversion. The following describes two methods for your reference. The strtotime function is used to
Some usages of strtotime functionThe realization principle of strtotime functionStrtotime ("-1 month") The reason for the evaluation failureSome usages of strtotime function1, Strtotime ("the") and Strtotime ("January")The effects of these two
In PHP to count the first day of the month and the last day we can use the Strtotime function to convert, the following two methods are described by friends to refer to.
The main use of the Strtotime function, powerful, supporting the relative date
Common PHP functions in project development. In order to facilitate storage, comparison, and transmission, we usually need to use the strtotime () function to convert a date to a UNIX timestamp, only PHP functions commonly used in project
Because I need to update the release date of a batch of data at work, if I want to update the data for 30 days from 20110112 today, we found that the strtotime function and date in the php Tutorial can easily implement the code. St...
Because I
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.