Loading core/java/android/text/format/DateFormat.java +51 −2 Original line number Diff line number Diff line Loading @@ -262,16 +262,65 @@ public class DateFormat { /** * Returns a {@link java.text.DateFormat} object that can format the date * in short form (such as 12/31/1999) according * to the current locale. * to the current locale and the user's date-order preference. * @param context the application context * @return the {@link java.text.DateFormat} object that properly formats the date. */ public static final java.text.DateFormat getDateFormat(Context context) { String value = Settings.System.getString(context.getContentResolver(), Settings.System.DATE_FORMAT); return getDateFormatForSetting(context, value); } /** * Returns a {@link java.text.DateFormat} object to format the date * as if the date format setting were set to <code>value</code>, * including null to use the locale's default format. * @param context the application context * @param value the date format setting string to interpret for * the current locale * @hide */ public static java.text.DateFormat getDateFormatForSetting(Context context, String value) { if (value != null) { int month = value.indexOf('M'); int day = value.indexOf('d'); int year = value.indexOf('y'); if (month >= 0 && day >= 0 && year >= 0) { String template = context.getString(R.string.numeric_date_template); if (year < month) { if (month < day) { value = String.format(template, "yyyy", "MM", "dd"); } else { value = String.format(template, "yyyy", "dd", "MM"); } } else if (month < day) { if (day < year) { value = String.format(template, "MM", "dd", "yyyy"); } else { // unlikely value = String.format(template, "MM", "yyyy", "dd"); } } else { // day < month if (month < year) { value = String.format(template, "dd", "MM", "yyyy"); } else { // unlikely value = String.format(template, "dd", "yyyy", "MM"); } } return new java.text.SimpleDateFormat(value); } } /* * The setting is not set; use the default. * We use a resource string here instead of just DateFormat.SHORT * so that we get a four-digit year instead a two-digit year. */ String value = context.getString(R.string.numeric_date_format); value = context.getString(R.string.numeric_date_format); return new java.text.SimpleDateFormat(value); } Loading core/res/res/values-ar-rEG/donottranslate-cldr.xml +1 −0 Original line number Diff line number Diff line Loading @@ -98,6 +98,7 @@ <string name="twenty_four_hour_time_format">H:mm</string> <string name="numeric_date">%-e/%-m/%Y</string> <string name="numeric_date_format">d/M/yyyy</string> <string name="numeric_date_template">"%s/%s/%s"</string> <string name="month_day_year">%-e %B، %Y</string> <string name="time_of_day">%-l:%M:%S %p</string> <string name="date_and_time">%-l:%M:%S %p %d/%m/%Y</string> Loading core/res/res/values-bg-rBG/donottranslate-cldr.xml +1 −0 Original line number Diff line number Diff line Loading @@ -98,6 +98,7 @@ <string name="twenty_four_hour_time_format">H:mm</string> <string name="numeric_date">%d.%m.%Y</string> <string name="numeric_date_format">dd.MM.yyyy</string> <string name="numeric_date_template">"%s.%s.%s"</string> <string name="month_day_year">%d %B %Y</string> <string name="time_of_day">%H:%M:%S</string> <string name="date_and_time">%H:%M:%S %d.%m.%Y</string> Loading core/res/res/values-ca-rES/donottranslate-cldr.xml +1 −0 Original line number Diff line number Diff line Loading @@ -98,6 +98,7 @@ <string name="twenty_four_hour_time_format">H:mm</string> <string name="numeric_date">%d/%m/%Y</string> <string name="numeric_date_format">dd/MM/yyyy</string> <string name="numeric_date_template">"%s/%s/%s"</string> <string name="month_day_year">%-e de %B de %Y</string> <string name="time_of_day">%-k:%M:%S</string> <string name="date_and_time">%-k:%M:%S %d/%m/%Y</string> Loading core/res/res/values-cs-rCZ/donottranslate-cldr.xml +1 −0 Original line number Diff line number Diff line Loading @@ -98,6 +98,7 @@ <string name="twenty_four_hour_time_format">H:mm</string> <string name="numeric_date">%-e.%-m.%Y</string> <string name="numeric_date_format">d.M.yyyy</string> <string name="numeric_date_template">"%s.%s.%s"</string> <string name="month_day_year">%-e. %B %Y</string> <string name="time_of_day">%-k:%M:%S</string> <string name="date_and_time">%-k:%M:%S %-e.%-m.%Y</string> Loading Loading
core/java/android/text/format/DateFormat.java +51 −2 Original line number Diff line number Diff line Loading @@ -262,16 +262,65 @@ public class DateFormat { /** * Returns a {@link java.text.DateFormat} object that can format the date * in short form (such as 12/31/1999) according * to the current locale. * to the current locale and the user's date-order preference. * @param context the application context * @return the {@link java.text.DateFormat} object that properly formats the date. */ public static final java.text.DateFormat getDateFormat(Context context) { String value = Settings.System.getString(context.getContentResolver(), Settings.System.DATE_FORMAT); return getDateFormatForSetting(context, value); } /** * Returns a {@link java.text.DateFormat} object to format the date * as if the date format setting were set to <code>value</code>, * including null to use the locale's default format. * @param context the application context * @param value the date format setting string to interpret for * the current locale * @hide */ public static java.text.DateFormat getDateFormatForSetting(Context context, String value) { if (value != null) { int month = value.indexOf('M'); int day = value.indexOf('d'); int year = value.indexOf('y'); if (month >= 0 && day >= 0 && year >= 0) { String template = context.getString(R.string.numeric_date_template); if (year < month) { if (month < day) { value = String.format(template, "yyyy", "MM", "dd"); } else { value = String.format(template, "yyyy", "dd", "MM"); } } else if (month < day) { if (day < year) { value = String.format(template, "MM", "dd", "yyyy"); } else { // unlikely value = String.format(template, "MM", "yyyy", "dd"); } } else { // day < month if (month < year) { value = String.format(template, "dd", "MM", "yyyy"); } else { // unlikely value = String.format(template, "dd", "yyyy", "MM"); } } return new java.text.SimpleDateFormat(value); } } /* * The setting is not set; use the default. * We use a resource string here instead of just DateFormat.SHORT * so that we get a four-digit year instead a two-digit year. */ String value = context.getString(R.string.numeric_date_format); value = context.getString(R.string.numeric_date_format); return new java.text.SimpleDateFormat(value); } Loading
core/res/res/values-ar-rEG/donottranslate-cldr.xml +1 −0 Original line number Diff line number Diff line Loading @@ -98,6 +98,7 @@ <string name="twenty_four_hour_time_format">H:mm</string> <string name="numeric_date">%-e/%-m/%Y</string> <string name="numeric_date_format">d/M/yyyy</string> <string name="numeric_date_template">"%s/%s/%s"</string> <string name="month_day_year">%-e %B، %Y</string> <string name="time_of_day">%-l:%M:%S %p</string> <string name="date_and_time">%-l:%M:%S %p %d/%m/%Y</string> Loading
core/res/res/values-bg-rBG/donottranslate-cldr.xml +1 −0 Original line number Diff line number Diff line Loading @@ -98,6 +98,7 @@ <string name="twenty_four_hour_time_format">H:mm</string> <string name="numeric_date">%d.%m.%Y</string> <string name="numeric_date_format">dd.MM.yyyy</string> <string name="numeric_date_template">"%s.%s.%s"</string> <string name="month_day_year">%d %B %Y</string> <string name="time_of_day">%H:%M:%S</string> <string name="date_and_time">%H:%M:%S %d.%m.%Y</string> Loading
core/res/res/values-ca-rES/donottranslate-cldr.xml +1 −0 Original line number Diff line number Diff line Loading @@ -98,6 +98,7 @@ <string name="twenty_four_hour_time_format">H:mm</string> <string name="numeric_date">%d/%m/%Y</string> <string name="numeric_date_format">dd/MM/yyyy</string> <string name="numeric_date_template">"%s/%s/%s"</string> <string name="month_day_year">%-e de %B de %Y</string> <string name="time_of_day">%-k:%M:%S</string> <string name="date_and_time">%-k:%M:%S %d/%m/%Y</string> Loading
core/res/res/values-cs-rCZ/donottranslate-cldr.xml +1 −0 Original line number Diff line number Diff line Loading @@ -98,6 +98,7 @@ <string name="twenty_four_hour_time_format">H:mm</string> <string name="numeric_date">%-e.%-m.%Y</string> <string name="numeric_date_format">d.M.yyyy</string> <string name="numeric_date_template">"%s.%s.%s"</string> <string name="month_day_year">%-e. %B %Y</string> <string name="time_of_day">%-k:%M:%S</string> <string name="date_and_time">%-k:%M:%S %-e.%-m.%Y</string> Loading