zoukankan      html  css  js  c++  java
  • Java——Date

    一、概念

    java.util.Date 表示特定的瞬间,精确到毫秒。

    二、Date类的构造方法

    2.1、public Date()

    创建的对象,表示的是当前计算机系统时间

    public class DateTest {
        public static void main(String[] args) throws ParseException {
            Date date = new Date();
            System.out.println(date);   // Fri May 14 15:29:33 CST 2021
        }
    }

    2.2、public Date(long t)

    可以指定毫秒创建Date对象,毫秒是从历元(1970-01-01 00:00:00)开始计算的时间。从这一刻开始计作0毫秒。

    public class DateTest {
        public static void main(String[] args) throws ParseException {
            long num = 1620977560284L;
            Date date = new Date(num);
            System.out.println(date);   // Fri May 14 15:32:40 CST 2021
        }
    }

    三、getTime

    public long getTime()

    getTime方法用来获取日期对象的毫秒值

    public class DateTest {
        public static void main(String[] args) throws ParseException {
            Date date = new Date();
            System.out.println(date.getTime());   // 1620977963498
        }
    }

    四、setTime

    public void setTime(long t)

    setTime方法用来给日期对象设置毫秒值

    public class DateTest {
        public static void main(String[] args) throws ParseException {
            Date date = new Date();
            date.setTime(1620977963498L);
            System.out.println(date);   // Fri May 14 15:39:23 CST 2021
        }
    }
    

      

      

  • 相关阅读:
    CS224d lecture 16札记
    CS224d lecture 15札记
    CS224d lecture 14札记
    CS224d lecture 13札记
    将博客搬至CSDN
    三张图理解JavaScript原型链
    三道题理解软件流水
    网络安全密码学课程笔记
    “wuliao“(无聊)聊天软件
    大二小学期C#资产管理大作业小记
  • 原文地址:https://www.cnblogs.com/xulinjun/p/14768810.html
Copyright © 2011-2022 走看看