提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
将日期转换为瞬间,反之亦然
import java.util.Date;//from NowJava.com - 时 代 Java import java.time.Instant; public class Main { public static void main(String[] args) { // Get the current date Date dt = new Date(); System.out.println("Date: " + dt); // Convert the Date to an Insatnt Instant in = dt.toInstant(); System.out.println("Instant: " + in); // Convert the Instant back to a Date Date dt2 = Date.from(in); System.out.println("Date: " + dt2); } }