package day0810;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;
public class CalendarDemo1 {
public static void main(String[] args) throws ParseException {
Calendar c = Calendar.getInstance();
//获取某个分量最大的值
int days1 = c.getActualMaximum(Calendar.DAY_OF_YEAR);//今年共多少天
int days2 = c.getActualMaximum(Calendar.DAY_OF_MONTH);//这个月多少天
System.out.println(days1+",,"+days2);
//15天后,如果15天前写-15
c.add(Calendar.DAY_OF_YEAR, 15);
//设定为那周五
c.set(Calendar.DAY_OF_WEEK, 6);
}
}
//------------------------------------
package day0810;
import java.util.Calendar;
import java.util.Date;
public class CalendarDemo2 {
public static void main(String[] args) {
//把日期设定为 2008-08-30 10:22:33
Calendar c = Calendar.getInstance();
c.set(Calendar.YEAR, 2008);
//Calendar的月是从0开始的,如果8月则可以写7,或者Calendar.AUGUST
c.set(Calendar.MONTH, Calendar.AUGUST);
c.set(Calendar.DAY_OF_MONTH, 30);
//Calendar.HOUR_OF_DAY是24小时制,
//Calendar.HOUR是分上下午的12小时值,建议使用Calendar.HOUR_OF_DAY
c.set(Calendar.HOUR_OF_DAY, 10);
c.set(Calendar.MINUTE, 22);
c.set(Calendar.SECOND, 33);
Date date = c.getTime();
System.out.println(date);
}
}
//-------------------------------------
Calendar Date SimpleDateFormat (2)
最新推荐文章于 2024-06-10 00:24:12 发布