What is the difference between PHP and the time stamp in JavaScript

Source: Internet
Author: User
Tags comparison php and php code

The time stamp in PHP is compared to the timestamp in JavaScript, in essence, they are the same thing, but if the two want to make an equal comparison, or a little different, a little attention, will go astray, so, here list easily overlooked two points different, for everyone to refer to:

1 unit problem: in PHP when the timestamp, mostly through the time () method to obtain, it gets the value is in seconds as the unit, and JavaScript from the Date object in the GetTime () method to obtain the value is in milliseconds, so, to compare their obtained Time is the same day, you must pay attention to their units converted to the same, 1 seconds =1000 milliseconds, the remaining, you understand, hehe.

2 time zone problem: The 1th said that in PHP, the time () method to obtain the timestamp, through the convenience of display, we will set up the current server in the PHP code time zone, such as the Chinese mainland server will normally be set into the East eight area, so the same, time () The method obtained is no longer from January 1, 1970 0:0 0 seconds, but from January 1, 1970 8:0 0 seconds, and JS usually does not make time zone related settings, so the January 1, 1970 0:0 0 seconds for the calculation of the starting point, so it is easy to create inconsistencies in this place.

Materialism tells us to look at nature through the phenomena of things, two timestamps, essentially, is the year, month, day, time, minutes, seconds of the combination of results, if the actual appearance and the expected results do not conform to its method, the best way is to their year, month, day and other values are lost, one by one comparison, it is easy to find the problem.

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/PHP/

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.