Date类,JavaSE

1. Introduction

Java also provides a system-independent encapsulation of date and time in the java.util.Date class. You can use the parameterless constructor in the Date class to create an instance for the current date and time. Its getTimeO method returns since GMT The time elapsed since January 1, 1970, its toStringO method returns a string of date and time.

2. Code

package com.zhuo.demo;

import java.util.Date;

public class Time {
    
    
    public static void main(String[] args) {
    
    
        Date date = new Date();
        System.out.println("从1970年1月1日起经过的时间是: " + date.getTime() + "毫秒");
        System.out.println("当前时间为: " + date.toString());
    }
}

Three. Running results

197011日起经过的时间是: 1613354529473毫秒
当前时间为: Mon Feb 15 10:02:09 CST 2021

Process finished with exit code 0

Guess you like

Origin blog.csdn.net/weixin_42768634/article/details/113813884