import javatextSimpleDateFormat;
import javautilCalendar;
import javautilDate;
import javautilScanner;
public class WeekDay {
public static final String FORMAT="yyyyMM";
public static javautilDate toDate(String dateStr) {
Date d=null;
SimpleDateFormat formater=new SimpleDateFormat(FORMAT);
try {
formatersetLenient(false);
d=formaterparse(dateStr);
} catch(Exception e) {
d=null;
}
return d;
}
public static int getFirstWeekdayOfMonth(int year, int month) {
Calendar c=CalendargetInstance();
csetFirstDayOfWeek(CalendarSATURDAY);
cset(year, month - 1, 1);
return cget(CalendarDAY_OF_WEEK);
}
public static void main(String[] args) {
Systemoutprintln("请输入年月:");
Scanner sc=new Scanner(Systemin);
String dateStr=scnextLine();
Date date=toDate(dateStr);
Calendar canlender=CalendargetInstance();
canlendersetTime(date);
int day=getFirstWeekdayOfMonth(canlenderYEAR, canlenderMONTH);
Calendar canlender2=CalendargetInstance();
canlender2set(canlenderget(CalendarYEAR), canlenderget(CalendarMONTH), day);
Calendar canlender3=CalendargetInstance();;
canlender3set(canlenderget(CalendarYEAR), canlenderget(CalendarMONTH), day + 1);
while(canlender2get(CalendarMONTH) == canlenderget(CalendarMONTH)) {
Systemoutprintln(canlender2get(CalendarDATE));
Systemoutprintln(canlender3get(CalendarDATE));
canlender2add(CalendarDATE, 7);
canlender3add(CalendarDATE, 7);
}
}
}
calendar读音:英 [ˈkælɪndə(r)],美 [ˈkælɪndər]。
calendar的意思:
n日历;挂历;日程表;记事本;(一年之中的)重大事件(或重要日期)一览表;历法。
v把…记入日程表中;把…列入表中;为(文件等)作分类索引。
复数:calendars。
记忆技巧:calend 每月第一天 + ar 表物 → 日历。
例句:
1、He marked off the days on a calendar
他划去日历上的日期。
2、There was a calendar on the wall above, with large squares around the dates
上面的墙上挂着日历,日期上画着大大的方框。
3、Winners will be selected at the end of each calendar month
每个月末都会选出优胜者。
4、Receiving sales forecast, and build the plant calendar and capacity plan
接收销售预测,并制定工厂日历及产能计划。
5、The fifth of May according to the lunar calendar is the Dragon Boat Festival
农历五月初五是端午节。
import javatextSimpleDateFormat;
import javautilCalendar;
import javautilDate;
public class Test {
public static void main(String[] args) {
SimpleDateFormat dateFormat =
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = getDate();
Systemoutprintln(dateFormatformat(date));
}
private static Date getDate() {
Calendar calendar = CalendargetInstance();//获得当前时间
calendaradd(CalendarSECOND, 20);//加20秒
return calendargetTime();//返回Date类
}
}
public static javautilDate toDate(String dateStr) {//将字符串格式化成日期
Date d=null;
SimpleDateFormat formater=new SimpleDateFormat("yyyy/MM/dd");
try {
formatersetLenient(false);
d=formaterparse(dateStr);
} catch(Exception e) {
d=null;
}
return d;
}
public static String formatDateTime(javautilDate date) {//将日期转成字符串
String result="";
SimpleDateFormat formater=new SimpleDateFormat("yyyy/MM/dd");
try {
result=formaterformat(date);
} catch(Exception e) {
}
return result;
}
public static int getFirstWeekdayOfMonth(int year, int month) {//求本月第一个周日
Calendar c=CalendargetInstance();
csetFirstDayOfWeek(CalendarSATURDAY);//周日第一天
cset(year, month - 1, 1);
return cget(CalendarDAY_OF_WEEK);
}
public static void main(String[] args) {
String startStr="2013/03/04";
Date start=toDate(startStr);
String endStr="2013/07/15";
Date end=toDate(endStr);
Calendar canlender=CalendargetInstance();
canlendersetTime(start);
int day=getFirstWeekdayOfMonth(canlenderYEAR, canlenderMONTH);
Calendar canlender2=CalendargetInstance();
canlender2set(canlenderget(CalendarYEAR), canlenderget(CalendarMONTH), day+1);//周一
while(canlender2getTime()before(start)){//如果本月第一个周一在开始日期之前
canlender2add(CalendarDATE, 7);
}
Calendar canlender3=CalendargetInstance();;
canlender3set(canlenderget(CalendarYEAR), canlenderget(CalendarMONTH), canlender2DATE+5);//周五
while(canlender2getTime()before(end)) {
Systemoutprintln("周一:"+formatDateTime(canlender2getTime()));
if(canlender3getTime()before(end)){
Systemoutprintln("周五:"+formatDateTime(canlender3getTime()));
}
canlender2add(CalendarDATE, 7);
canlender3add(CalendarDATE, 7);
}
}
以上就是关于java 算当月休息日全部的内容,包括:java 算当月休息日、calendar英语怎么读、java如何在现有时间加上20s等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)