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 thisDay = (cal0.get(Calendar.DAY_OF_MONTH) == cal1.get(Calendar.DAY_OF_MONTH));
if (withDate) {
String skeleton = (thisMonth && thisYear ? "MMM-d" : "Y-M-d") + (withTime ? " Hm" : "");
String format = android.text.format.DateFormat.getBestDateTimePattern(Locale.getDefault(), skeleton);
return new SimpleDateFormat(format).format(millis);
try {
String skeleton = (thisMonth && thisYear ? "MMM-d" : "yyyy-M-d") + (withTime ? " Hm" : "");
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)
return getTimeInstance(context, SimpleDateFormat.SHORT).format(millis);
else