• 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
        }
    }
    
  • 相关阅读:
    Oracle Sql优化之日期的处理
    python excel转xml
    3、vue项目里引入jquery和bootstrap
    1、vue.js开发环境搭建
    2、vue-router2使用
    go 初步
    一个全局变量引起的DLL崩溃
    在linux用gdb查看stl中的数据结构
    gdb看core常用命令
    redis常用命令
  • 原文地址:https://www.cnblogs.com/lemonlover/p/14062570.html
Copyright © 2020-2023  润新知