zoukankan      html  css  js  c++  java
  • Day14_Date类

    Date类

    • Date表示特定的瞬间,精确到毫秒。Date类中的大部分方法都已经被Calendar类中的方法所取代。
    • 时间单位
      • 1秒=1000毫秒
      • 1毫秒=1000微秒
      • 1微秒=1000纳秒
    package com.oop.Demo11;
    
    import java.util.Date;
    
    public class Demo08 {
        public static void main(String[] args) {
            //1、创建date对象
            Date date1 = new Date ();
            //today
            System.out.println (date1.toString ());
            System.out.println (date1.toLocaleString ());
            //yesterday
            Date date2=new Date (date1.getTime ()-(60*60*24*1000));
            System.out.println (date2.toLocaleString ());
            //方法after、before
            boolean b1=date1.after (date2);
            System.out.println (b1);//true
            boolean b2=date1.before (date2);
            System.out.println (b2);//false
            //比较compareTo();
            /**compareTo()原码
             * public int compareTo(Date anotherDate) {
             *         long thisTime = getMillisOf(this);
             *         long anotherTime = getMillisOf(anotherDate);
             *         return (thisTime<anotherTime ? -1 : (thisTime==anotherTime ? 0 : 1));
             *     }
             *前边的小返回-1,相等返回0;前边的大返回1
             */
            int i=date1.compareTo (date2);
            System.out.println (i);//1
            //比较是否相等equals
            boolean b3=date1.equals (date2);
            System.out.println (b3);//false
        }
    }
    
  • 相关阅读:
    5、文件处理
    6、Python模块
    4、字典使用
    3、列表 list
    1、Python基础
    2、循环判断
    配置LOG4J(log4j-1.2.17)
    File /WEB-INF/web.xml not found...
    关于TOMCAT的 ROOT/WEB-INF/web.xml的配置
    tomcat 配置系列3
  • 原文地址:https://www.cnblogs.com/lemonlover/p/14062570.html
Copyright © 2011-2022 走看看