Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get preferred date format string of Android system

Tags:

android

Does anybody know how to get the format string used by the system when formatting a date using

DateFormat.getLongDateFormat(Context context).format(Date date) 
like image 238
Androrider Avatar asked Feb 10 '12 22:02

Androrider


People also ask

What is SimpleDateFormat in Android?

SimpleDateFormat is a concrete class for formatting and parsing dates in a locale-sensitive manner. It allows for formatting (date → text), parsing (text → date), and normalization. SimpleDateFormat allows you to start by choosing any user-defined patterns for date-time formatting.

How do I get the date on my Android?

getInstance(). getTime(); System. out. println("Current time => " + c); SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy"); String formattedDate = df.


1 Answers

To get the date format pattern you can do:

Format dateFormat = android.text.format.DateFormat.getDateFormat(getApplicationContext()); String pattern = ((SimpleDateFormat) dateFormat).toLocalizedPattern(); 
like image 196
Mark Melling Avatar answered Oct 18 '22 01:10

Mark Melling