PHP strtotime Application Experience _php Tutorial

Source: Internet
Author: User

Strtotime (Date ("y-m-01 00:00:00")); Used to get the first day of the month time stamp

In the actual PHP strtotime application suddenly once encountered the conversion time is 8 hours slower than the actual time! I thought it was in php.ini.

TimeZone Setup error caused, patrol a lap finally locked the problem on the Strtotime function (Linux server is often a problem, the Windows server returned the data is basically correct)

Read the PHP manual carefully and find that the first parameter has a format requirement

Time

The string to parse, according to the gnu»date Input Formats syntax. Before PHP 5.0.0, microseconds weren ' t allowed in the time, since PHP 5.0.0 they is allowed but ignored.

Further follow-up discovery of Date Input Formats

$ lc_all=c tz=utc0 Date
Mon Mar 1 00:21:42 UTC 2004
$ tz=utc0 Date + '%y-%m-%d%h:%m:%sz '
2004-03-01 00:21:42z
$ Date--iso-8601=ns | TR T ' #--iso-8601 is a GNU extension.
2004-02-29 16:21:42,692722128-0800
$ date--rfc-2822 # a GNU extension
Sun, Feb 2004 16:21:42-0800
$ date + '%y-%m-%d%h:%m:%s%z ' #%z is a GNU extension.
2004-02-29 16:21:42-0800
$ date + ' @%s.%n ' #%s and%N are GNU extensions.
@1078100502.692722128

Find our usual format Yyyy-mm-dd HH:II:SS does not meet the requirements. After a rough look, decide to use the UTC0 format to update the above code with the following code
Strtotime (Date ("Y-m-01 00:00:00"). " Z "); Used to get the first day of the month time stamp
Solve this problem!

PHP Strtotime Application Summary:

We were sometimes supported by the system during the development process and overlooked some of the details. As this example in the Windows platform does not have this problem, but the PHP strtotime application still need to follow the specification will be better. To avoid such problems.


http://www.bkjia.com/PHPjc/445988.html www.bkjia.com true http://www.bkjia.com/PHPjc/445988.html techarticle strtotime (Date (y-m-01 00:00:00));//used to get the first day of the month time stamp in the actual PHP strtotime application suddenly once encountered the conversion over time is 8 hours slower than the actual time ...

  • Contact Us

    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.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.