package day14;

import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;

import java.util.Calendar;
import java.util.Scanner;

/**
* Created by admin on 2018/11/24.
* * Calendar:它为特定瞬间与一组诸如 YEAR、MONTH、DAY_OF_MONTH、HOUR 等 日历字段之间的转换提供了一些方法,并为操作日历字段(例如获得下星期的日期)提供了一些方法。
*
* public int get(int field):返回给定日历字段的值。日历类中的每个日历字段都是静态的成员变量,并且是int类型。

*/
public class CalenderDemo {
public static void main(String[] args) {
Calendar rightNow = Calendar.getInstance();
//获取当前时间
int year = rightNow.get(Calendar.YEAR);
int month = rightNow.get(Calendar.MONTH);
int date = rightNow.get(Calendar.DATE);
System.out.println(year + "-" + (month+1) + "-" + date);
//获取5年后的今天的前五天
rightNow.add(Calendar.YEAR, 5);
rightNow.add(Calendar.DATE, -5);
int year2 = rightNow.get(Calendar.YEAR);
int month2 = rightNow.get(Calendar.MONTH);
int date2 = rightNow.get(Calendar.DATE);
System.out.println(year2+ "-" + (month2+1) + "-" + date2);
//计算每年的2月最后一天
Scanner sc = new Scanner(System.in);
int year3 = sc.nextInt();
rightNow.set(year3, 2, 1);
rightNow.add(Calendar.DATE, -1);
System.out.println(rightNow.get(Calendar.DATE));
}
}