喜糖

移动开发工程师 。涉及 android、ios、jni

导航

获得今天是周几的代码

Posted on 2011-07-28 16:13  喜糖  阅读(325)  评论(0编辑  收藏  举报

public class GetDayOfWeek{
public static void main(String args[]){
final String dayNames[] = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五","星期六" };
Calendar calendar = Calendar.getInstance();
Date date = new Date();
//calendar.setTime(date);
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK)-1;
//if(dayOfWeek <0)dayOfWeek=0;
System.out.println(dayNames[dayOfWeek]);
}

 

默认情况下。

calendar.get(Calendar.DAY_OF_WEEK)活动的枚举值中Sunday为1,Monday为2.以此类推