Fixed skeleton date/time format

This commit is contained in:
M66B 2023-09-21 19:03:51 +02:00
parent f54bbe198a
commit 69085ee096
1 changed files with 11 additions and 3 deletions

View File

@ -2171,9 +2171,17 @@ public class Helper {
boolean thisMonth = (cal0.get(Calendar.MONTH) == cal1.get(Calendar.MONTH)); boolean thisMonth = (cal0.get(Calendar.MONTH) == cal1.get(Calendar.MONTH));
boolean thisDay = (cal0.get(Calendar.DAY_OF_MONTH) == cal1.get(Calendar.DAY_OF_MONTH)); boolean thisDay = (cal0.get(Calendar.DAY_OF_MONTH) == cal1.get(Calendar.DAY_OF_MONTH));
if (withDate) { if (withDate) {
String skeleton = (thisMonth && thisYear ? "MMM-d" : "Y-M-d") + (withTime ? " Hm" : ""); try {
String format = android.text.format.DateFormat.getBestDateTimePattern(Locale.getDefault(), skeleton); String skeleton = (thisMonth && thisYear ? "MMM-d" : "yyyy-M-d") + (withTime ? " Hm" : "");
return new SimpleDateFormat(format).format(millis); String format = android.text.format.DateFormat.getBestDateTimePattern(Locale.getDefault(), skeleton);
return new SimpleDateFormat(format).format(millis);
} catch (Throwable ex) {
Log.e(ex);
if (withTime)
return getDateTimeInstance(context).format(millis);
else
return getDateInstance(context).format(millis);
}
} else if (thisYear && thisMonth && thisDay) } else if (thisYear && thisMonth && thisDay)
return getTimeInstance(context, SimpleDateFormat.SHORT).format(millis); return getTimeInstance(context, SimpleDateFormat.SHORT).format(millis);
else else