System.currentTimeMillis()
is most effective if your primary concern is performance. Date()
must be close in terms of performance because it is just an encapsulator of a value (long) in milliseconds.
The Calendar
class is comparatively slower and much more complex resulting from the need to deal with all the inherent characteristics of the date and time (leap years, summer / winter time adjustments, different time zones, etc.).
In conclusion:
- If the main concern is performance then it suggested
System.currentTimeMillis () '.
-
To perform calculations or to format dates for the user would suggest
the use of the Calendar class because of its flexibility. It has a
getInstance
method that returns an implementation according to the
settings (region / location) of the device.
For example, if the device is configured for a
location in Europe or America will return a calendar
Gregorian.
Its use is simple:
Calendar c = Calendar.getInstance();
Date data = c.getTime();
The method getInstance
returns a 'calendar' initialized with the
date and time in accordance with the local settings of the
device.
Finally, Time class has been declared obsolete since API Level 22 and the earlier page of the API itself warned against its use due to various problems that had been detected and recommended using the Calendar or GregorianCalendar class.
This class has a number of issues and it is recommended that
GregorianCalendar is used instead.