zoukankan      html  css  js  c++  java
  • LocalDate获取当天,本月第一天,本月最后一天,今年第一天,今年最后一天

     使用jdk1.8的LocalDate获取当天,本月第一天,本月最后一天,今年第一天,今年最后一天

    LocalDate localDate = LocalDate.now();
    //今天
    Date day = Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
    //这个月的第一天
    Date monthStart = Date.from(localDate.with(TemporalAdjusters.firstDayOfMonth()).atStartOfDay(ZoneId.systemDefault()).toInstant());
    //这个月的最后一天 下个月的第一天
    Date monthEnd = Date.from(localDate.plusMonths(1).with(TemporalAdjusters.firstDayOfMonth()).atStartOfDay(ZoneId.systemDefault()).toInstant());
    //今年的第一天
    Date yearStart = Date.from(localDate.with(TemporalAdjusters.firstDayOfYear()).atStartOfDay(ZoneId.systemDefault()).toInstant());
    //今年的最后一天 下一年的第一天
    Date yearEnd = Date.from(localDate.plusYears(1).with(TemporalAdjusters.firstDayOfYear()).atStartOfDay(ZoneId.systemDefault()).toInstant());
  • 相关阅读:
    HTTP——Web服务器、代理、缓存
    nginx配置文件详解2
    nginx配置文件详解
    shell笔记2
    django笔记
    python 发请求,urllib,urllib2
    nginx配置
    python os模块学习
    mac 终端命令小结
    mac常用命令笔记
  • 原文地址:https://www.cnblogs.com/haoyul/p/13502514.html
Copyright © 2011-2022 走看看