zoukankan      html  css  js  c++  java
  • Calendar类

    下面使用对象调用get()方法来获取年月日字段

    get

    public int get​(int field)
    返回给定日历字段的值。 在宽大模式下,所有日历字段都被归一化。 在非宽泛模式下,所有日历字段都被验证,如果任何日历字段具有超出范围的值,该方法将抛出异常。 归一化和验证由complete()方法处理,该过程是与日历系统相关的。
    参数
    field - 给定的日历字段。
    结果
    给定日历字段的值。
    异常
    ArrayIndexOutOfBoundsException - 如果指定的字段超出范围( field < 0 || field >= FIELD_COUNT )。
    另请参见:
    set(int,int)complete()
    package com.Test01;
    
    import java.util.Calendar;
    
    public class CalendarDemo {
        public static void main(String[] args) {
            //获取对象
            Calendar c = Calendar.getInstance();
            System.out.println(c);
    //        public int get​(int field)
            int year = c.get(Calendar.YEAR);
            int month = c.get(Calendar.MONTH)+1;
            int date = c.get(Calendar.DATE);
            System.out.println(year+"年"+month+"月"+date+"日");
    
        }
    }
    

     

    package com.Test01;
    
    import java.util.Calendar;
    
    public class CalendarDemo {
        public static void main(String[] args) {
            //获取对象
            Calendar c = Calendar.getInstance();
            System.out.println(c);
    //        public int get​(int field)
            c.add(Calendar.YEAR,2);
            c.add(Calendar.MONTH,-1);
            
            c.set(2050,11,25);
            
            
            int year = c.get(Calendar.YEAR);
            int month = c.get(Calendar.MONTH)+1;
            int date = c.get(Calendar.DATE);
            System.out.println(year+"年"+month+"月"+date+"日");
    
        }
    }
    

     字段格式:Calendar.YEAR or MONTH or DATE;

  • 相关阅读:
    UDP and netstat
    UDP learn by Python3
    UDP headers and checksum
    routetrace
    IPv4 headers
    Commands for IP
    IP checksum
    POJ 3667 Hotel 线段树处理区间信息
    【枚举】Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017) Div2C题
    二分图最大匹配模板 HDU1083
  • 原文地址:https://www.cnblogs.com/lsswudi/p/11405414.html
Copyright © 2011-2022 走看看