The following code is givi开发者_JS百科ng very bad performance. I've come to know that there are performance problems with the Calendar API
long startInMilliSec = measFileCreationTime_OssTime;
Calendar thisMoment = Calendar.getInstance();
long currentInMilliSec = thisMoment.getTime().getTime();
if (currentInMilliSec >= startInMilliSec) {
return (true);
} else {
return (false);
}
Is there any alternative for this?
you can use System.currentTimeMillis()
to get the current time in millis since Dec, 1st 1970. Subtracting two millis values can be used to get the duration in millis between them. Calendar needs only to be used when interpreting the year, Month etc of such a milli value.
If you want to be even more precise, then you could use System.nanoTime()
to get nano precision. The absolute nano value has no particular meaning in this case and can only be used for calculating time differences between subsequently taken nano values.
精彩评论