zoukankan      html  css  js  c++  java
  • LocalDateTime 格式的起止时间

    public class LocalDateTimeUtil extends cn.hutool.core.date.LocalDateTimeUtil {
    
        private static String[] parsePatterns = {
                "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM",
                "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM",
                "yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM"};

    public static long between(LocalDate startTimeInclude, LocalDate endTimeExclude, ChronoUnit unit) { return between(LocalDateTime.of(startTimeInclude, LocalTime.MIN), LocalDateTime.of(endTimeExclude, LocalTime.MIN), unit); } /** * t1 是否晚于 t2 * * @param t1 * @param t2 * @return */ public static boolean isAfter(LocalDateTime t1, LocalDateTime t2) { return t1.compareTo(t2) > 0; } /** * t1 是否晚于 t2 * * @param t1 * @param t2 * @return */ public static boolean isAfter(LocalDate t1, LocalDate t2) { return t1.compareTo(t2) > 0; } /** * t1 是否晚于 t2 * * @param t1 * @param t2 * @return */ public static boolean isAfterEqual(LocalDateTime t1, LocalDateTime t2) { return t1.compareTo(t2) >= 0; } /** * t1 是否晚于 t2 * * @param t1 * @param t2 * @return */ public static boolean isAfterEqual(LocalDate t1, LocalDate t2) { return t1.compareTo(t2) >= 0; } /** * t1 是否早于 t2 * * @param t1 * @param t2 * @return */ public static boolean isBefore(LocalDate t1, LocalDate t2) { return t1.compareTo(t2) < 0; } /** * t1 是否早于 t2 * * @param t1 * @param t2 * @return */ public static boolean isBefore(LocalDateTime t1, LocalDateTime t2) { return t1.compareTo(t2) < 0; } /** * t1 是否早于 t2 * * @param t1 * @param t2 * @return */ public static boolean isBeforeEqual(LocalDateTime t1, LocalDateTime t2) { return t1.compareTo(t2) <= 0; } /** * t1 是否早于 t2 * * @param t1 * @param t2 * @return */ public static boolean isBeforeEqual(LocalDate t1, LocalDate t2) { return t1.compareTo(t2) <= 0; } /** * 获取服务器启动时间 */ public static LocalDateTime getServerStartDate() { long time = ManagementFactory.getRuntimeMXBean().getStartTime(); return LocalDateTimeUtil.of(time); } /** * 日期型字符串转化为日期 格式 */ public static LocalDateTime parseOldDate(Object str) { if (str == null) { return null; } try { return LocalDateTimeUtil.of(org.apache.commons.lang3.time.DateUtils.parseDate(str.toString(), parsePatterns)); } catch (ParseException e) { return null; } } /** * 判断是否为同一天 * * @param startTime * @param endTime * @return */ public static boolean sameDay(LocalDateTime startTime, LocalDateTime endTime) { return sameDay(startTime.toLocalDate(), endTime.toLocalDate()); } /** * 判断是否为同一天 * * @param startTime * @param endTime * @return */ public static boolean sameDay(LocalDate startTime, LocalDate endTime) { return startTime.equals(endTime); } public static LocalDate getStartDayOfWeek(LocalDate today) { return getStartDayOfWeek(LocalDateTime.of(today, LocalTime.MIN)).toLocalDate(); } public static LocalDate getEndDayOfWeek(LocalDate today) { return getEndDayOfWeek(LocalDateTime.of(today, LocalTime.MAX)).toLocalDate(); } /** * 获取 日期 本周的开始时间 * * @param today * @return */ public static LocalDateTime getStartDayOfWeek(LocalDateTime today) { LocalDateTime resDate = LocalDateTime.now(); if (today == null) { today = resDate; } DayOfWeek week = today.getDayOfWeek(); int value = week.getValue(); resDate = today.minusDays(value - 1); return LocalDateTime.of(resDate.toLocalDate(), LocalTime.MIN); } /** * 获取 日期 本周的结束时间 * * @param today * @return */ public static LocalDateTime getEndDayOfWeek(LocalDateTime today) { LocalDateTime resDate = LocalDateTime.now(); if (today == null) { today = resDate; } DayOfWeek week = today.getDayOfWeek(); int value = week.getValue(); resDate = today.plusDays(7 - value); return LocalDateTime.of(resDate.toLocalDate(), LocalTime.MAX); } }
  • 相关阅读:
    开启chrome默认支持ipv6
    IC6151试用发现的问题
    锁存器(latch)、触发器(Flipflop)、寄存器(register)的区别
    文件管理小习惯:在特定位置创建快捷方式
    采用SPI接口的芯片
    阅读笔记:TI Grounding in mixedsignal systems demystified, Part 1
    IC6151使用小技巧,摸索中。。。
    基于RBAC模型的权限管理系统的设计和实现(转载)
    Cron 表达式说明
    组织结构及授权系统关系
  • 原文地址:https://www.cnblogs.com/bookc/p/14652327.html
Copyright © 2011-2022 走看看