zoukankan      html  css  js  c++  java
  • jdk 8 日期处理。

    ZoneId id = ZoneId.systemDefault();
    LocalDateTime dateTime = LocalDateTime.now(id);
    System.out.println("时区ID:"+id);
    System.out.println("当前时间:"+dateTime);
    
    LocalDateTime addYear = dateTime.plus(1, ChronoUnit.YEARS);
    System.out.println("当前时间加1年:"+addYear);
    
    LocalDateTime addDay = dateTime.plusDays(56);
    System.out.println("距56天后是几号:"+addDay);
    
    System.out.println("从默认时区的系统获取当前日期时间:"+ZonedDateTime.now());
    String now = "2018-09-01";
    String now1 = "2019-09-01 11:12:23";
    
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
    DateTimeFormatter formatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    
    LocalDate nowTime = LocalDate.parse(now,formatter);
    LocalDateTime nowTime1 = LocalDateTime.parse(now1,formatter1);
    
    System.out.println("yyyy-MM-dd 字符串转时间:"+nowTime);
    System.out.println("yyyy-MM-dd HH:mm:ss 字符串转时间:"+nowTime1);
    
    Long now2 = System.currentTimeMillis();
    LocalDateTime date = LocalDateTime.ofEpochSecond(now2/1000,0,ZoneOffset.ofHours(8));
    System.out.println("时间戳转时间:"+date);
    
    LocalDateTime startDateTime = LocalDateTime.of(2018,9,19,23,34,12);
    LocalDateTime endDateTime = LocalDateTime.of(2018,9,15,4,34,12);
    System.out.println("手动构造开始时间:"+startDateTime);
    System.out.println("手动构造结束时间:"+endDateTime);
    Duration duration = Duration.between(endDateTime,startDateTime);
    System.out.printf("时间1,时间2相差:%s天%n",duration.toDays());
    System.out.printf("时间1,时间2相差:%s分钟%n",duration.toMinutes());
    
    LocalDate startDate = LocalDate.of(2018,10,19);
    LocalDate endDate = LocalDate.of(2018,9,15);
    
    Period period = Period.between(endDate,startDate);
    System.out.printf("日期1,日期2相差:%s天%n",period.getDays());
    
    System.out.println("本月有多少天:"+YearMonth.now().lengthOfMonth());
    System.out.println("今年有多少天:"+YearMonth.now().lengthOfYear());








  • 相关阅读:
    Linux 线程间通信方式+进程通信方式 总结
    使用opencv第三方库的makefile文件示例
    rplidar SDK 二次开发---之获取目标信息(0.1)
    #include "Target_orientation.h"
    opencv —— 调用摄像头采集图像 VideoCapture capture(0);
    cmake 支持-lpthread
    ROS下sensor_msgs::ImagePtr到sensor_msgs::Image之间的转换
    JAVA 校验身份证号码工具类(支持15位和18位)
    python面向对象游戏练习:好人坏人手枪手榴弹
    python 私有属性的作用
  • 原文地址:https://www.cnblogs.com/1-Admin/p/9636836.html
Copyright © 2011-2022 走看看