Instant

 /**
     * java.time.Instant jdk1.8
     * public final class Instant
        implements Temporal, TemporalAdjuster, Comparable<Instant>, Serializable {}
                   方法:
              now():从系统时钟中获得当前时刻。
              getEpochSecond():返回秒数;
              ofEpochMilli(long epochMilli);返回毫秒 Instant实例
              转换:Instant   ---->   util.Date
          util.Date --->    Instant
          String    ------> Instant
     */
    
    
    Instant now1=Instant.now();//2019-07-19T01:25:22.894Z
    long epochSecond = now1.getEpochSecond();//返回秒数;
     //Instant---->util.Date
     Date date = new Date(epochSecond*1000);//毫秒数
     /*使用SimpleDateFormat 格式化*/
     SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
     String format = sdf.format(date);
     System.out.println(format);
     
     //util.Date---->Instant
     Date date2 = new Date();
     long time = date2.getTime();//返回毫秒
     Instant ofEpochMilli = Instant.ofEpochMilli(time);//返回毫秒 Instant实例
     long epochSecond2 = ofEpochMilli.getEpochSecond();//返回秒数
     String format2 = sdf.format(new Date(epochSecond2*1000));
     System.out.println(format2);
     
     //String---->Instant
     Instant parse4 = Instant.parse("2019-07-12T07:15:08.564Z");
     System.out.println(parse4);
     

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值