java怎么用if语句判断星期几
发布网友
发布时间:1小时前
我来回答
共1个回答
热心网友
时间:2024-10-03 19:21
public static void main(String[] args) {
Date date = new Date();
String week = date.toString().substring(0, 3);
if (week.equals("Mon")) {
//do some thing
} else if (week.equals("Tue")) {
//do some thing
} else if (week.equals("Wed")) {
//do some thing
} else if (week.equals("Thu")) {
//do some thing
} else if (week.equals("Fri")) {
//do some thing
} else if (week.equals("Sat")) {
//do some thing
} else if (week.equals("Sun")) {
//do some thing
}
}
java怎么用if语句判断星期几
String week = date.toString().substring(0, 3); if (week.equals("Mon")) { //do some thing } else if (week.equals("Tue")) { //do some thing } else if (week.equals("Wed")) { //do some thing } else if (week.equals("Thu")) { //do some thing } else if (week.equals(...
java 给一个日期判断是星期几
/** * 判断当前日期是星期几 * * @param pTime 修要判断的时间 * @return dayForWeek 判断结果 * @Exception 发生异常 */ public static int dayForWeek(String pTime) throws Exception { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); Calendar c ...
java用数字输入0到6用中文表示星期几
直接上代码。public static void main(String[] args) { String yourInput = args[0];if(yourInput.equals("0")) System.out.println("星期日");if(yourInput.equals("1")) System.out.println("星期一");if(yourInput.equals("2")) System.out.println("星期二");if(yourInput.equ...
java中如何获取日期时间中的星期几?
a、使用Calendar类 //根据日期取得星期几 public static String getWeek(Date date){ String[] weeks = {"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};Calendar cal = Calendar.getInstance();cal.setTime(date);int week_index = cal.get(Calendar.DAY_OF_WEEK) ...
java 怎么计算明天是星期几?
if(w==1)System.out.print("星期天");if(w==2)System.out.print("星期一");if(w==3)System.out.print("星期二");if(w==4)System.out.print("星期三");if(w==5)System.out.print("星期四");if(w==6)System.out.print("星期五");if(w==7)System.out.print("星期六");...
java中如何获取日期时间中的星期几?
if (w < 0){ w = 0;} return weekOfDays[w];} 调用方法如下,看你怎么用了 public static void main(String[] args){ //今天是2015-10-19 星期一 String weekOfDate = null; //参数为null时表示获取当前日期是星期几 weekOfDate = getWeekOfDate(null);System.out.println(weekOfDate...
java 某年某月第几周第几天 是几月几号
//dayOfWeek+1 就是星期几(星期日 为 1)if(i_week_day == 1){ sumDay = (weekOfMonth-1)*7 + dayOfWeek+1;}else{ sumDay = 7-i_week_day+1 + (weekOfMonth-1)*7 + dayOfWeek +1;} //在1号的基础上加上相应的天数 c.set(Calendar.DATE, sumDay);SimpleDateFormat sf2 = ...
java怎样通过日期获取星期几?
1、使用Calendar类\x0d\x0a/**\x0d\x0a* 获取当前日期是星期几\x0d\x0a*\x0d\x0a* @param dt\x0d\x0a* @return 当前日期是星期几\x0d\x0a*/\x0d\x0apublic static String getWeekOfDate(Date dt) {\x0d\x0aString[] weekDays = {"星期日", "星期一", "星期二"...
java怎么通过日期获取星期几
1、使用Calendar类 / 获取当前日期是星期几 param dt return 当前日期是星期几 / public static String getWeekOfDate(Date dt) { String[] weekDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};Calendar cal = Calendar.getInstance();cal.setTime(...
java 怎么根据一天的时间得到一周的时间
return 返回一个代表当期日期是星期几的数字。1表示星期天、2表示星期一、7表示星期六。/ public static int getDayOfWeek(String year, String month, String day) { Calendar cal = new GregorianCalendar(new Integer(year).intValue(),new Integer(month).intValue() - 1, new Integer(day).int...