• java.util.Calendar


    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));
        }
    }
  • 相关阅读:
    提交按钮变灰
    解析spring启动加载dubbo过程
    shiro的SecurityUtis
    spring集成shiro登陆流程(下)
    spring集成shiro登陆流程(上)
    shiro的DelegatingFilterProxy怎么找到ShiroFilterFactoryBean
    sql多表关联
    android常用控件
    android控件之EditText
    浅议iOS网络数据解析
  • 原文地址:https://www.cnblogs.com/royfans/p/10012497.html
Copyright © 2020-2023  润新知