Java 简明教程
Java Date Class
Introduction
Java Util Date 类表示一个具体的时间点,精确到毫秒。
The Java Util Date class represents a specific instant in time, with millisecond precision.
Class declaration
以下是 java.util.Date 类的声明:
Following is the declaration for java.util.Date class −
public class Date
extends Object
implements Serializable, Cloneable, Comparable<Date>
Methods inherited
此类从以下类中继承方法:
This class inherits methods from the following classes −
-
java.util.Object
Creating a Date instance of current date Example
此 Java 示例演示了 Date class 的 from() 方法以获取当前时间的 Date 实例。
This Java example demonstrates the from() method of Date class to get Date instance of current time.
package com.tutorialspoint;
import java.time.Instant;
// Import the Date package
import java.util.Date;
// Main public class
public class DateDemo {
public static void main(String[] args) {
// create a date of current time
Date date = Date.from(Instant.now());
// print the date instance
System.out.println("Date: " + date.toString());
}
}