Sun*_*wal 6 android calendar date
我希望从Java Date
对象获取星期几,当我有一个Date
String 数组时,我.
SimpleDateFormat sourceDateformat = new SimpleDateFormat("yyyy-MM-dd");
public String[] temp_date;
public Int[] day = new Int[5];
Date[] d1= new Date[5];
Calendar[] cal= new Calendar[5]
try {
d1[i]= sourceDateformat.parse(temp_date[i].toString());
cal[i].setTime(d1[i]); // its not compiling this line..showing error on this line
day[i]= cal[i].get(Calendar.DAY_OF_WEEK);
}
catch (ParseException e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
有谁知道答案吗?
Phi*_*oda 25
你可以得到像这样的日整数:
Calendar c = Calendar.getInstance();
c.setTime(yourdate); // yourdate is an object of type Date
int dayOfWeek = c.get(Calendar.DAY_OF_WEEK); // this will for example return 3 for tuesday
Run Code Online (Sandbox Code Playgroud)
如果您需要输出为"Tue"而不是3,而不是通过日历,只需重新格式化字符串:new SimpleDateFormat("EE").format(date)
(EE表示"星期几,短版")
取自这里:如何通过传递具体日期来确定星期几?
归档时间: |
|
查看次数: |
17206 次 |
最近记录: |