How to use the date format that has been setup as

2019-06-19 10:51发布

问题:

As you probably know, you can setup date format in the Settings of an Android device.

In code how do we make sure that we use that format for date display?

回答1:

Try android.text.format.DateFormat, notably getDateFormatOrder() to get the user's preferred date format.



回答2:

You can retrieve both the date format as well as the time format like this:

DateFormat timeFormat;
DateFormat dateFormat;

dateFormat = android.text.format.DateFormat.getDateFormat(context);
timeFormat = android.text.format.DateFormat.getTimeFormat(context);