System.currenttimemillis () unit conversion of calculation mode and time

Source: Internet
Author: User

Catalogue [-]

    • One, the unit conversion of time
    • Second, System.currenttimemillis () calculation method
One, the unit conversion of time

1 seconds =1000 milliseconds (ms) 1 msec =1/1,000 sec (s)
1 sec =1,000,000 microseconds (μs) 1 μs =1/1,000,000 sec (s)
1 sec =1,000,000,000 ns 1 nanoseconds =1/1,000,000,000 sec (s)
1 sec =1,000,000,000,000 Picosecond (PS) 1 picosecond =1/1,000,000,000,000 sec (s)

1 minutes = 60 seconds

1 hours =60 minutes =3600 seconds

Second, System.currenttimemillis () calculation method

In the development process, many people are usually accustomed to using new date () to get the current time. What new Date () does is actually called System.currenttimemillis (). If it is just a need or a millisecond, then you can use System.currenttimemillis () instead of the new Date (), which is a bit more efficient. If you need to use the new Date () multiple times in the same method, the performance is typically 1.1-point consumption, where you can actually declare a reference.

Small example:

You can see that the output time is one hours after the current time.

System.currenttimemillis () +3600*1000) can be interpreted this way: System.currenttimemillis () is equivalent to milliseconds, but after 1000, it becomes in seconds. Then, 3,600 seconds = 1 hours, so the output is 1 hours after the current time.

We can control it this way: System.currenttimemillis () +time*1000), the incoming time is in seconds, when passed in 60, the output: one minute after the current time

You can see that the output time is one minute after the current time.

System.currenttimemillis () unit conversion of calculation mode and time

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.