根据“年月日”字符串,判断这一天是星期几

来源:互联网 发布:淘宝怎么账号登陆 编辑:程序博客网 时间:2024/06/06 18:37

需求:页面传来一个年月日的字符串,根据这个字符串判断这一天是星期几

代码:

public class TestCalender {@Testpublic void testCalender() throws Exception{SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");   Calendar c = Calendar.getInstance();   c.setTime(format.parse("2016-3-21"));  //判断方法 int dayForWeek = 0;   if(c.get(Calendar.DAY_OF_WEEK) == 1){    dayForWeek = 7;   }else{    dayForWeek = c.get(Calendar.DAY_OF_WEEK) - 1;   }  System.out.println(dayForWeek);}}

结果:1

0 0
原创粉丝点击