美文网首页
JDK1.8 LocalDateTime

JDK1.8 LocalDateTime

作者: 忘记_3a6a | 来源:发表于2019-12-23 20:01 被阅读0次
      LocalDateTime rightNow=LocalDateTime.now();
            System.out.println("当前时间:"+rightNow);
            System.out.println(String.format("某一年的第%s天",rightNow.getDayOfYear()));
            System.out.println(String.format("当前月份:"+rightNow.getMonth()));
    
            System.out.println(String.format("%s年",rightNow.getYear()));
            System.out.println(String.format("%s月",rightNow.getMonthValue()));
            System.out.println(String.format("%s日",rightNow.getDayOfMonth()));
            System.out.println(String.format("%s时",rightNow.getHour()));
            System.out.println(String.format("%s分",rightNow.getMinute()));
            System.out.println(String.format("%s秒",rightNow.getSecond()));
            System.out.println(String.format("%s纳秒",rightNow.getNano()));
            System.out.println(String.format("%s星期",rightNow.getDayOfWeek()));
    
            LocalDateTime ofTime=LocalDateTime.of(2019,12,12,10,9,30);
            System.out.println("自定义时间:"+ofTime);
    
            System.out.println("减法");
            System.out.println(ofTime.minusYears(1));
            System.out.println("加法");
            System.out.println(ofTime.plus(20, ChronoUnit.NANOS));
    
            System.out.println(rightNow.format(DateTimeFormatter.ISO_DATE));
            System.out.println(rightNow.format(DateTimeFormatter.ofPattern("yyyy年MM月dd日")));
    
            System.out.println(LocalDateTime.parse("2019-12-12 10:09:30",DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
    

    相关文章

      网友评论

          本文标题:JDK1.8 LocalDateTime

          本文链接:https://www.haomeiwen.com/subject/bgjtoctx.html