zoukankan      html  css  js  c++  java
  • Calendar

    import java.util.Calendar;
    /*Calendar类:
     * public int get(int field)  返回给定日历字段的值。
     * public static Calendar getInstance()  使用默认时区和语言环境获得一个日历。
     * 返回的 Calendar 基于当前时间,使用了默认时区和默认语言环境。
     *
     *  abstract  void add(int field, int amount)
              根据日历的规则,为给定的日历字段  添加或减去  指定的时间量。
        void set(int year, int month, int date)
              设置日历字段 YEAR、MONTH 和 DAY_OF_MONTH 的值。 
     */
    public class CalendarDemo1 {
     public static void main(String[] args) {
      // 返回 Calendar 基于当前时间
      Calendar now = Calendar.getInstance(); // 返回子类对象
      // 获取年
      int year = now.get(Calendar.YEAR);
      // 获取月
      int month = now.get(Calendar.MONTH);
      // 获取天
      int day = now.get(Calendar.DATE);
      System.out.println(year + "年" + month + "月" + day + "日"); // 因为month从0开始
      System.out.println("*************************");
      
      now.add(Calendar.YEAR, -5);
      year = now.get(Calendar.YEAR);
      month = now.get(Calendar.MONTH);
      day = now.get(Calendar.DATE);
      System.out.println(year + "年" + month + "月" + day + "日");
      System.out.println("*************************");
      now.set(22, 22,34);
      year = now.get(Calendar.YEAR);
      month = now.get(Calendar.MONTH);
      day = now.get(Calendar.DATE);
      System.out.println(year + "年" + month + "月" + day + "日");
     }
    }
  • 相关阅读:
    1070 结绳
    1069 微博转发抽奖
    1068 万绿丛中一点红
    1067 试密码
    1066 图像过滤
    1065 单身狗
    CSS--文本溢出与换行
    css--滤镜filter
    css--flex布局
    css--table布局
  • 原文地址:https://www.cnblogs.com/rong123/p/9887407.html
Copyright © 2011-2022 走看看