本文介绍了获取星期几的GregorianCalendar的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有个约会,我需要知道星期几,所以我用一个GregorianCalendar对象,但我取回一些日期是不正确。
的GregorianCalendar日历=新的GregorianCalendar(年,月,日);
INT I = calendar.get(Calendar.DAY_OF_WEEK);
我是什么做错了吗?
谢谢!
编辑答案:
mont--;
GregorianCalendar的日历=新的GregorianCalendar(年,月,日);
INT I = calendar.get(Calendar.DAY_OF_WEEK);
如果(ⅰ== 2){
dayOfTheWeek =星期一;
}否则,如果(我== 3){
dayOfTheWeek =星期二;
}否则,如果(我== 4){
dayOfTheWeek =星期三;
}否则,如果(我== 5){
dayOfTheWeek =星期四;
}否则,如果(我== 6){
dayOfTheWeek =星期五;
}否则,如果(我== 7){
dayOfTheWeek =星期六;
}否则如果(ⅰ== 1){
dayOfTheWeek =太阳报;
}
解决方案
时区时区= TimeZone.getDefault();
台历挂历=新的GregorianCalendar(时区);
calendar.set(年,月,日,时,分,秒);
串MONTHNAME = calendar.getDisplayName(Calendar.MONTH,Calendar.SHORT,Locale.getDefault()); // Locale.US);
串DAYNAME = calendar.getDisplayName(Calendar.DAY_OF_WEEK,Calendar.SHORT,Locale.getDefault()); // Locale.US);
I have a date and I need to know the day of the week, so I used a GregorianCalendar object but I get back some dates that are incorrect.
GregorianCalendar calendar = new GregorianCalendar(year, month, day);
int i = calendar.get(Calendar.DAY_OF_WEEK);
What am I doing wrong?
Thanks!
EDIT SOLUTION:
mont--;
GregorianCalendar calendar = new GregorianCalendar(year, month, day);
int i = calendar.get(Calendar.DAY_OF_WEEK);
if(i == 2){
dayOfTheWeek = "Mon";
} else if (i==3){
dayOfTheWeek = "Tue";
} else if (i==4){
dayOfTheWeek = "Wed";
} else if (i==5){
dayOfTheWeek = "Thu";
} else if (i==6){
dayOfTheWeek = "Fri";
} else if (i==7){
dayOfTheWeek = "Sat";
} else if (i==1){
dayOfTheWeek = "Sun";
}
解决方案
TimeZone timezone = TimeZone.getDefault();
Calendar calendar = new GregorianCalendar(timezone);
calendar.set(year, month, day, hour, minute, second);
String monthName=calendar.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.getDefault());//Locale.US);
String dayName=calendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, Locale.getDefault());//Locale.US);
这篇关于获取星期几的GregorianCalendar的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!