I am saving a Date to SharedPreferences so it needs to be saved as a string. That's fine. However, I need to display this date (more specifically the time) at a later point.
I would like the time to be displayed in 12 hour or 24 inline with the system displayed preference. The problem is that I can't find a method of doing this. There are some answers floating around to check date patterns for "am" or "pm" or even "h". Another answer what to use: `DateFormat.is24Hour(). But this does not seem to exist anymore (I can't find out to get that method anywhere!)
What's the best method to solve this?
There are two classes named
DateFormat
:java.text.DateFormat
android.text.format.DateFormat
The method
is24HourFormat()
is found only inandroid.text.format.DateFormat
class. You only have to pay attention importing the correct class.