gpt4 book ai didi

java - Android日历获取当前星期几作为字符串

转载 作者:IT老高 更新时间:2023-10-28 20:48:38 25 4
gpt4 key购买 nike

我试图以这种方式获取一个带有实际工作日名称的字符串:

            Calendar c = Calendar.getInstance();
int dayOfWeek = c.get(Calendar.DAY_OF_WEEK);

if (c.get(Calendar.MONDAY) == dayOfWeek) weekDay = "monday";
else if (c.get(Calendar.TUESDAY) == dayOfWeek) weekDay = "tuesday";
else if (c.get(Calendar.WEDNESDAY) == dayOfWeek) weekDay = "wednesday";
else if (c.get(Calendar.THURSDAY) == dayOfWeek) weekDay = "thursday";
else if (c.get(Calendar.FRIDAY) == dayOfWeek) weekDay = "friday";
else if (c.get(Calendar.SATURDAY) == dayOfWeek) weekDay = "saturday";
else if (c.get(Calendar.SUNDAY) == dayOfWeek) weekDay = "sunday";

weekDay 始终为空,我实际上不知道为什么,因为调试器说 dayOfWeek 是 5,所以我应该等于 c.get( Calendar.THURSDAY)

最佳答案

就这么简单

sCalendar = Calendar.getInstance();
String dayLongName = sCalendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.getDefault());

关于java - Android日历获取当前星期几作为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18256521/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com