dateformat 在 flutter 中显示工作日的错误文本输出
我遇到了一个问题,就像这个问题一样,但没有答案。
首先,我的代码带有 int 值,结果是正确的:
List<int> listeWeekday() {
List<int> gesamteWeekdays = [];
String date;
for (int d = 1; d <= dateMonth; d++) {
if (d < 10) {
date = wochenTag.format('yyyy-MM-0$d');
} else {
date = wochenTag.format('yyyy-MM-$d');
}
DateTime dateTimeObject = DateTime.parse(date);
var dateTimeOWeekday = dateTimeObject.weekday;
gesamteWeekdays.add(dateTimeOWeekday
);
}
return gesamteWeekdays;
}
结果:(
I/flutter (17056): Inhalt der Liste weekday:[2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1]
月份是二月,所以天数和工作日的数量是正确的)
现在是问题。当我尝试将工作日的数字转换为文本时,它无法正常工作:
List<String> listeWeekday() {
List<String> gesamteWeekdays = [];
String date;
for (int d = 1; d <= dateMonth; d++) {
if (d < 10) {
date = wochenTag.format('yyyy-MM-0$d');
} else {
date = wochenTag.format('yyyy-MM-$d');
}
DateTime dateTimeObject = DateTime.parse(date);
var dateTimeOWeekday = dateTimeObject.weekday;
var dateTimeOweekdayEEE =
DateFormat('E', 'de_DE').format(DateTime(dateTimeOWeekday));
gesamteWeekdays.add(
dateTimeOweekdayEEE,
);
}
return gesamteWeekdays;
}
结果:
I/flutter (17056): Inhalt der Liste weekday:[Di, Mi, Do, Sa, So, Mo, Mo, Di, Mi, Do, Sa, So, Mo, Mo, Di, Mi, Do, Sa, So, Mo, Mo, Di, Mi, Do, Sa, So, Mo, Mo]
结果中没有星期五,但星期一两次(在 en-us 语言环境中存在相同的问题,因此德语语言环境不是问题)。
有人知道如何解决这个问题吗? 非常感谢,
最诚挚的问候 帕特里克
I'm facing a problem, as in this question, but there is no answer.
first of all my code with int values, where the result ist correct:
List<int> listeWeekday() {
List<int> gesamteWeekdays = [];
String date;
for (int d = 1; d <= dateMonth; d++) {
if (d < 10) {
date = wochenTag.format('yyyy-MM-0$d');
} else {
date = wochenTag.format('yyyy-MM-$d');
}
DateTime dateTimeObject = DateTime.parse(date);
var dateTimeOWeekday = dateTimeObject.weekday;
gesamteWeekdays.add(dateTimeOWeekday
);
}
return gesamteWeekdays;
}
result:
I/flutter (17056): Inhalt der Liste weekday:[2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1]
(the month ist February, so the quantity of days and the number of the weekday ist correct)
Now the problem. When I try to convert the number of the weekday into text it doesn't work properly:
List<String> listeWeekday() {
List<String> gesamteWeekdays = [];
String date;
for (int d = 1; d <= dateMonth; d++) {
if (d < 10) {
date = wochenTag.format('yyyy-MM-0$d');
} else {
date = wochenTag.format('yyyy-MM-$d');
}
DateTime dateTimeObject = DateTime.parse(date);
var dateTimeOWeekday = dateTimeObject.weekday;
var dateTimeOweekdayEEE =
DateFormat('E', 'de_DE').format(DateTime(dateTimeOWeekday));
gesamteWeekdays.add(
dateTimeOweekdayEEE,
);
}
return gesamteWeekdays;
}
result:
I/flutter (17056): Inhalt der Liste weekday:[Di, Mi, Do, Sa, So, Mo, Mo, Di, Mi, Do, Sa, So, Mo, Mo, Di, Mi, Do, Sa, So, Mo, Mo, Di, Mi, Do, Sa, So, Mo, Mo]
in the result there ist no Friday, but the Monday two times (in the locale en-us there is the same issue, so the german locale is not the problem).
Does anybody have an idea how to resolve this problem?
Thank you very much,
Best regards
Patrick
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论