formatA static method
Timeline like QQ.
today (HH:mm) yesterday (昨天;Yesterday) this week (星期一,周一;Monday,Mon) others (yyyy-MM-dd)
Implementation
static String formatA(
int ms, {
int? locMs,
String formatToday = 'HH:mm',
String format = 'yyyy-MM-dd',
String languageCode = 'en',
bool short = false,
}) {
int locTimeMs = locMs ?? DateTime.now().millisecondsSinceEpoch;
int elapsed = locTimeMs - ms;
if (elapsed < 0) {
return DateUtil.formatDateMs(ms, format: formatToday);
}
if (DateUtil.isToday(ms, locMs: locTimeMs)) {
return DateUtil.formatDateMs(ms, format: formatToday);
}
if (DateUtil.isYesterdayByMs(ms, locTimeMs)) {
return languageCode == 'zh' ? '昨天' : 'Yesterday';
}
if (DateUtil.isWeek(ms, locMs: locTimeMs)) {
return DateUtil.getWeekdayByMs(ms,
languageCode: languageCode, short: short);
}
return DateUtil.formatDateMs(ms, format: format);
}