System.currentTimeMillis()
is the most efficient if your main concern is performance. Date()
should be close in terms of performance as it is only an encapsulator of a (long) value in thousandths of a second.
The class Calendar
is comparatively slower and rather more complex resulting from the need to deal with all characteristics inherent in the representation of the date and time (leap years, adjustments for summer/winter time, different time zones, etc).
In conclusion:
- if the main concern is the performance then suggested
System.currentTimeMillis()`.
To perform calculations or format dates for the user would suggest
the use of class Calendar due to its flexibility. It has a
method getInstance
which returns an implementation according to the
regional definitions (region/geographical 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
current date and time according to local definitions of the
device.
Finally, the class Team is declared obsolete since API Level 22 and already earlier, the API page itself warned against its use due to various problems that had been detected and recommended the use of the Calendar or Gregoriancalendar class.
This class has a number of issues and it is Recommended that
Gregoriancalendar is used Instead.
Depends on what you intend to do :)
– Renan Gomes
I just want to take the date in a simple and efficient way. As I saw several different opinions, different codes, I was confused. The idea is to take the date and store in a String, and in another String store the time.
– Renan Lazarotto