Java 简明教程
Java Date Class
Class declaration
以下是 java.util.Date 类的声明:
public class Date
extends Object
implements Serializable, Cloneable, Comparable<Date>
Creating a Date instance of current date Example
此 Java 示例演示了 Date class 的 from() 方法以获取当前时间的 Date 实例。
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());
}
}