让以下内容从我的SQL中读取日期,并将星期几作为数字返回。
Calendar c = Calendar.getInstance();
c.setTime(rs.getDate("ShipmentDate"));
int DayOfWeek = c.get(Calendar.DAY_OF_WEEK);
这很好用。
如何将结果(0,1,2,3,4,5,6)转换为(周日,周一,周二,周三,周四,周五,周六)?
示例我使用数组捏了上面提到的代码,虽然没有给出任何示例。
答案 0 :(得分:0)
String[] dayToString = {
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
}
字母
int day = ...;
String strDay = dayToString(day);
答案 1 :(得分:0)
String[] days = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
<强>输出:强>
System.out.println(days[0]); //--> "Sun"
System.out.println(days[1]); //--> "Mon"
依旧......
在您的示例中:
int DayOfWeek = c.get(Calendar.DAY_OF_WEEK);
String dayString = days[DayOfWeek];