Java基础~Java Instant类

2022-12-01 08:28:17

一、介绍

  • Instant类由一个静态的工厂方法now()可以返回当前时间戳
  • 时间戳是包含日期和时间的,与java.util.Date很类似,事实上Instant就是类似JDK8以前的Date
  • Instant和Date这两个类可以进行转换

二、实例

publicstaticvoidmain(String[] args){
    Instant instant= Instant.now();
    System.out.println("当前时间戳是:"+instant);

    Date date= Date.from(instant);
    System.out.println("当前时间戳是:"+date);

    instant= date.toInstant();
    System.out.println("当前时间戳是:"+instant);}
  • 作者:飞Link
  • 原文链接:https://blog.csdn.net/feizuiku0116/article/details/123335384
    更新时间:2022-12-01 08:28:17