Use new Date () and System.currenttimemillis () in Java to get the difference between the current timestamp (Java Advanced-performance boost)

Source: Internet
Author: User

In the development process, often many people are accustomed to use the new date () to get the current time, it is more convenient to use, but also to get the current time related to all aspects of information, such as get hours, minutes and so on, but also can format the output, contains the information is relatively rich. But sometimes you don't need to get that much information, you just have to care about the number of milliseconds it returns, such as gettime (). In order to get this timestamp, many people also like to use the new date (). GetTime () to get, I see no problem, but in fact there is no need. In fact, look at the Java source code will know:

 Public Date () {    this(System.currenttimemillis ());}

It's already obvious that what new Date () is doing is actually calling 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. And many people like to use the new Date () multiple times in the same method, usually the performance is 1.1 points to consume, here can actually declare a reference.

Reference:

http://blog.csdn.net/sunhuaqiang1/article/details/49867085 (the above content is transferred from this article)

Http://blog.csdn.net/column/details/java1989.html (His other Java advanced articles)

Use new Date () and System.currenttimemillis () in Java to get the difference between the current timestamp (GO) (Java Advanced-performance boost)

Related Article

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.