How to deal with php output timestamp mismatch in js _ javascript skills

Source: Internet
Author: User
The JS timestamp is 13 BITs, which contains 3 bits in milliseconds, while PHP only has 10 bits out of milliseconds, which is why it is not correct, the processing method is as follows: the timestamp imported by PHP for JS processing. Why can't I always get the correct number? The original JS timestamp is 13 BITs, which contains 3 bits in milliseconds, PHP only contains 10 characters, excluding milliseconds.

Var nowtime = (new Date ). getTime ();/* Current timestamp * // * conversion time, calculation difference */function comptime (beginTime, endTime) {var secondNum = parseInt (endTime-beginTime * 1000) /1000); // calculate the timestamp difference if (secondNum> = 0 & secondNum <60) {return secondNum + 'Seconds before ';} else if (secondNum >=60 & secondNum <3600) {var nTime = parseInt (secondNum/60); return nTime + 'minutes ago ';} else if (secondNum> = 3600 & secondNum <3600*24) {var nTime = parseInt (secondNum/3600); return nTime + 'hour before ';} else {var nTime = parseInt (secondNum/86400); return nTime + 'day before ';} t = comptime (timestamp, nowtime ); // timestamp is the timestamp returned by PHP via ajax

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.