• LocalDateUtil


    
    package com.izkml.mlyun.uc.user.util;
    
    import com.zkml.common.util.MyUtil;
    
    import java.time.*;
    import java.time.format.DateTimeFormatter;
    import java.util.Date;
    
    /**
     * @author fanghui
     * @create 2020-4-8 18:38
     **/
    public class LocalDateUtil {
    
        /**
         * @param localDate
         * @return
         * @Author: fanghui
         * @Date: 2020-04-08 05:21:59
         * @Description: LocalDate转Date
         **/
        public static Date localDate2Date(LocalDate localDate) {
            if (null == localDate) {
                return null;
            }
            ZonedDateTime zonedDateTime = localDate.atStartOfDay(ZoneId.systemDefault());
            return Date.from(zonedDateTime.toInstant());
    
        }
    
        /**
         * @param date
         * @return
         * @Author: fanghui
         * @Date: 2020-04-08 05:21:51
         * @Description: Date转LocalDate
         **/
        public static LocalDate date2LocalDate(Date date) {
            if (null == date) {
                return null;
            }
            return date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
    
        }
    
        /**
         * @param date
         * @return
         * @Author: fanghui
         * @Date: 2020-04-08 05:22:09
         * @Description: Date转换为LocalDateTime
         **/
        public static LocalDateTime date2LocalDateTime(Date date) {
            Instant instant = date.toInstant();
            ZoneId zoneId = ZoneId.systemDefault();
            LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();
            return localDateTime;
        }
    
        /**
         * @param localDateTime
         * @return
         * @Author: fanghui
         * @Date: 2020-04-08 05:22:54
         * @Description: LocalDateTime转换为Date
         **/
        public static Date localDateTime2Date(LocalDateTime localDateTime) {
            ZoneId zoneId = ZoneId.systemDefault();
            ZonedDateTime zdt = localDateTime.atZone(zoneId);
            Date date = Date.from(zdt.toInstant());
            return date;
        }
    
        public static LocalDateTime strTranslocalDateTime(String str) {
            if (MyUtil.isBlank(str)) {
                return null;
            }
            DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
            LocalDateTime ldt = LocalDateTime.parse(str, df);
            return ldt;
        }
    
        public static String localDateTimeTransStr(LocalDateTime localDateTime) {
            if (MyUtil.isBlank(localDateTime)) {
                return null;
            }
            DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
            String localTime = df.format(localDateTime);
            return localTime;
        }
    }
    
    
    
  • 相关阅读:
    使用WCF实现SOA面向服务编程—— 架构设计
    ASP.NET MVC 4 RC的JS/CSS打包压缩功能
    自定义WCF的配置文件
    C#综合揭秘——分部类和分部方法
    结合领域驱动设计的SOA分布式软件架构
    【转】数字证书类型
    kubeadm部署单master Kuberntes集群
    持续交付
    编译在docker alpine中可用的go程序
    百度云盘,文件重命名
  • 原文地址:https://www.cnblogs.com/fangh816/p/13295556.html
Copyright © 2020-2023  润新知