PHP millisecond timestamp calculation method, PHP How to get millisecond timestamp

Source: Internet
Author: User
Tags timestamp example
PHP Get millisecond Timestamp example, PHP programming time function can get timestamp, compare PHP get millisecond timestamp of different writing and efficiency, interested friends reference.

PHP Millisecond Timestamp calculation method

The time () function in PHP gets the timestamp, in seconds.

Front-end JS gets the timestamp in milliseconds.

How to unify the time stamp of JS and PHP, that is, how to get millisecond timestamp using PHP?

Example:

Copy Codecode example: "; Echo getmillisecond_new (). ' PHP milliseconds-getmillisecond_new () ';/** idea: * 1. Use Microtime () to obtain a microsecond timestamp, format: 0.69718900 1420440552* 2. Add the front and back parts x1000, then round round ($ float,0) * seconds time () and milliseconds-to-microseconds microtime (), 22 is 1000 binary * This way, the timestamp of the front-end JS can be consistent * js:new date (). GetTime () get millisecond timestamp */? > <title>Time</title>

Run Result: 1424069168633 php milliseconds-getmillisecond () 1424069168633 php milliseconds-getmillisecond_new () 1424069168643 JS get millisecond timestamp can be seen, The third timestamp value is slightly larger than the first two, which is the time that the code runs and is normal.

  • 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.