getWeekday static method
get WeekDay. dateTime isUtc languageCode zh or en short
Implementation
static String getWeekday(DateTime? dateTime,
{String languageCode = 'en', bool short = false}) {
if (dateTime == null) return "";
String weekday = "";
switch (dateTime.weekday) {
case 1:
weekday = languageCode == 'zh' ? '星期一' : 'Monday';
break;
case 2:
weekday = languageCode == 'zh' ? '星期二' : 'Tuesday';
break;
case 3:
weekday = languageCode == 'zh' ? '星期三' : 'Wednesday';
break;
case 4:
weekday = languageCode == 'zh' ? '星期四' : 'Thursday';
break;
case 5:
weekday = languageCode == 'zh' ? '星期五' : 'Friday';
break;
case 6:
weekday = languageCode == 'zh' ? '星期六' : 'Saturday';
break;
case 7:
weekday = languageCode == 'zh' ? '星期日' : 'Sunday';
break;
default:
break;
}
return languageCode == 'zh'
? (short ? weekday.replaceAll('星期', '周') : weekday)
: weekday.substring(0, short ? 3 : weekday.length);
}