Comparison between the timestamp in php and the timestamp in javascript

Source: Internet
Author: User

The comparison between the timestamps in php and the timestamps in javascript is essentially the same, but it is still a little different if the two are to be compared equally, this will go astray. Therefore, the two differences that are easy to ignore are listed here for your reference:

1) unit problem: most of the time stamps in php are obtained through the time () method, and the value is measured in seconds, in javascript, the value obtained from the getTime () method of the Date object is in milliseconds. Therefore, we need to compare whether the obtained time is the same day, you must note that they are converted to the same unit, 1 second = 1000 milliseconds, the remaining, You know, huh, huh.

2) time Zone problem: As mentioned in the first point, the time () method is used in php to obtain the timestamp. For ease of display, we set the time zone of the current server in the php code, for example, servers in mainland China are usually set to the UTC + 8 zone. In this way, the time () method is no longer obtained from 00:00:00 on January 1, January 1, 1970, but from 08:00:00 on January 1, January 1, 1970, js usually does not set the time zone. Therefore, it starts from 00:00:00, January 1, January 1, 1970, so it is easy to cause inconsistency in this place.

Materialism tells us that we need to look at the essence of things through the phenomena. The two timestamps are essentially the combination of years, months, days, hours, minutes, and seconds, if the results do not match the expected results, the best way is to output the values of the year, month, and day, and compare them one by one, it is easy to find the problem.

 

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.