"Xia lingzhu" in PHP"

Source: Internet
Author: User

Today, I met a big monster named Xia lingworm.

He is not proficient in learning because he has fallen into the trap. The pitfalls are dug like this:

In the past, I used the following statements to indicate "tomorrow" and "day after tomorrow" of the current time:

$ Date = date (time + 3600*24 * N );

But this writing method is not safe. Please refer to the example below:


 

Ini_set ('date. timezone ', 'Europe/Berlin'); echo date ("Y-m-d H: I: s", 1382824800); echo "<br/> "; echo date ("Y-m-d H: I: s", 1382824800 + 1*86400); ini_set ('date. timezone ', 'Europe/Berlin'); echo date ("Y-m-d H: I: s", 1382824800); echo "<br/> "; echo date ("Y-m-d H: I: s", 1382824800 + 1*86400 );

The output result is


 

00:00:00 23:00:00 23:00:00


The next day was secretly eaten for an hour!

In addition, this will happen in the next 154 days. It will not be "Returned" until 155th days ".

Why does it look like this? After querying the data, we found that the problem was originally caused by timeout,

However, if we do not implement failover in China, this issue will not become a problem for the moment for "Asia/Shanghai.

We recommend that you use more scientific calculation methods for date formatting.

 


Previously written PHP code may cause a BUG. Here, I apologize to the previous project.

 

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.