import javatextParseException;
import javatextSimpleDateFormat;
import javautilCalendar;
import javautilDate;
public class DateTime {
public static void main(String[] args) throws ParseException {
DateTime dt = new DateTime();
Date date = new SimpleDateFormat("yyyy-MM-dd")parse("2008-02-14");
date = dtlastDayOfMonth(date);
Systemoutprintln (new SimpleDateFormat("yyyy-MM-dd")format(date));
date = new SimpleDateFormat("yyyy-MM-dd")parse("2008-02-14");
date = dtlastDayOfMonth2(date);
Systemoutprintln (new SimpleDateFormat("yyyy-MM-dd")format(date));
date = new SimpleDateFormat("yyyy-MM-dd")parse("2008-02-14");
date = dtlastDayOfMonth3(date);
Systemoutprintln (new SimpleDateFormat("yyyy-MM-dd")format(date));
date = new SimpleDateFormat("yyyy-MM-dd")parse("2008-02-14");
date = dtlastDayOfMonth4(date);
Systemoutprintln (new SimpleDateFormat("yyyy-MM-dd")format(date));
}
public Date lastDayOfMonth(Date date) {
Calendar cal = CalendargetInstance();
calsetTime(date);
calset(CalendarDAY_OF_MONTH, 1);
calroll(CalendarDAY_OF_MONTH, -1);
return calgetTime();
}
public Date lastDayOfMonth2(Date date) {
Calendar cal = CalendargetInstance();
calsetTime(date);
int value = calgetActualMaximum(CalendarDAY_OF_MONTH);
calset(CalendarDAY_OF_MONTH, value);
return calgetTime();
}
public Date lastDayOfMonth3(Date date) {
Calendar cal = CalendargetInstance();
calsetTime(date);
calset(CalendarDAY_OF_MONTH, 1);
caladd(CalendarMONTH, 1);
caladd(CalendarDATE, -1);
return calgetTime();
}
public Date lastDayOfMonth4(Date date) {
Calendar cal = CalendargetInstance();
calsetTime(date);
do {
caladd(CalendarDATE, 1);
}
while (calget(CalendarDATE) != 1);
caladd(CalendarDATE, -1);
return calgetTime();
}
}
以上就是关于java怎么算出当月和上去年这个月的值怎么算全部的内容,包括:java怎么算出当月和上去年这个月的值怎么算、、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)