设置、获取时间里的某一个选项时,使用Calendat
public static void main(String[] args)
{
// TODO Auto-generated method stub
//通过Calendar 操作时间
//得到日历对象
//日历对象是单例模式,只有一个对象
Calendar calendar = Calendar.getInstance(Locale.CHINA);
System.out.println(calendar.getTimeInMillis());
//设置日历显示的时间
calendar.set(2000, 3, 15, 9, 14);
System.out.println(calendar.getTimeInMillis());
//练习:9.10到目前为止多少天
long oneDay = 1*1000*60*60*24;
calendar.set(2017, 10,16,10,16);
long now = calendar.getTimeInMillis();
calendar.set(2017, 9,10,1,1);
long old = calendar.getTimeInMillis();
int day = (int) ((now-old)/oneDay);
System.out.println(day);
//获取系统当前时间
System.out.println(calendar.getTime());
//获取系统时区
System.out.println(calendar.getTimeZone());
//可以 格式化时间
Calendar c = new GregorianCalendar();
//设置时区并输出
c.setTimeZone(TimeZone.getTimeZone("CST"));
System.out.println(c.getTimeZone());
//在new出的对象中格式化时间
SimpleDateFormat sdf = new SimpleDateFormat();
sdf.applyPattern("yyyy/MM/dd HH:mm:ss");
String strTime = sdf.format(c.getTime());
System.out.println(strTime);
//Date Calender 怎么选择?
//获取系统时间 Date(格式化时间)
//设置时间 Calendar 获取时间里的某个选项
}