• java Calendar日历类


    ~Calendar类是一个抽象类,为特定瞬间与一组诸如YEAR,MONTH,DAY_OF_MONTH,HOUR等日历字段之间的转换提供了一些方
    法,并为操作日历字段(例如获得下星期的日期)提供了一些方法,瞬间可用毫秒值来表示,它是距历元(1970年1月1日的
    00:00:00.000的偏移量)
    ~与其他语言环境敏感类一样,Calendar提供了一个类方法getInstance,已获得此类型的一个通用的对象。Calendar的
    getInstancefangfa fanhui yige Calendar对象,其日历字段已由当前日期和时间初始化

    public static Calendar getInstance()
    public final Date getTime()
    public final void setTime(Date date)
    public int get(int field)
    public finalvoid set(int year,int month,int date)
    public boolean befor(Object when)
    public boolean aafter(Object when)
    public int compareTo(Calendar anotherCalendar)

    import java.util.Calendar;
    public class CalendarDemo {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            Calendar calendar = Calendar.getInstance();
            System.out.print(calendar.get(Calendar.YEAR)+"年");
            System.out.print(calendar.get(Calendar.MONTH)+"月");
            System.out.print(calendar.get(Calendar.DATE)+"日");
            System.out.print(calendar.get(Calendar.HOUR_OF_DAY)+":");//24小时制
            System.out.print(calendar.get(Calendar.MINUTE)+":");
            System.out.println(calendar.get(Calendar.SECOND));
            calendar.set(Calendar.YEAR, 2020);
            System.out.println(calendar.get(Calendar.YEAR)+"年");
            System.out.println(calendar.getTimeInMillis());//1970年到现在过去了的秒数
        }
    }
  • 相关阅读:
    Design and Analysis of Algorithms_Decrease-and-Conquer
    TCPL 札记
    谬论:64 = 65?
    二叉树内部顶点与外部顶点在数量上的关系
    Design and Analysis of Algorithms_Divide-and-Conquer
    LeetCode 36. Valid Sudoku
    LeetCode 58. Length of Last Word
    LeetCode 66. Plus One
    LeetCode 67. Add Binary
    LeetCode 70. Climbing Stairs
  • 原文地址:https://www.cnblogs.com/liubing2018/p/8489504.html
Copyright © 2020-2023  润新知