"standard" is a very abstract concept, specially in computing, and even more with Date time, and I've seen people doing all type of crazy things, I'll answer what I believe is the best way of dealing with it.
manipulation:
For general manipulation during Runtime handling of time you should use a Calendar
object, either using the static Calender.getInstance()
or directly instantiating a GregorianCalendar
with new
. There're several other classes that deal with the same problem like Time
or Date
but all of them are either limited or not recommended anymore.
With this class you can use to compare, transform, set values, etc.
on screen representation/format:
To format a representation of the Calendar
on screen (a String) you can use either a DateFormat
or a SimpleDateFormat
. They will make the human readable value you need to show on screen, by calling DateFormat.format(calendar.getTime());
save/restore:
Last but not least, if you want to save this value (in a SharedPreferences, SQL database, or anywhere) you should use a long
as UNIX EPOCH. Number of milliseconds since 1/1/1970. To get the current value on Runtime you can use System.currentTimeMillis()
or to set/extract from a Calendar
is as simple as Calendar.getTimeInMillis()
Calendar.setTimeInMillis(long milliseconds)