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.
Java gets the current timestamp using new Date () and System.currenttimemillis ()