创建一个Date对象-
Date date = new Date();
现在,将ZonedId设置为默认值-
final ZoneId id = ZoneId.systemDefault();
将java.util.date转换为ZonedDateTime-
System.out.println(ZonedDateTime.ofInstant(date.toInstant(), id));
import java.time.ZoneId; import java.time.ZonedDateTime; import java.util.Date; public class Demo { public static void main(String[] args) { Date date = new Date(); final ZoneId id = ZoneId.systemDefault(); System.out.println(ZonedDateTime.ofInstant(date.toInstant(), id)); } }
输出结果
2019-04-19T00:37:33.344+05:30[Asia/Calcutta]