• java时间工具类,时间相互转换


    /*
     * @author XueWeiWei
     * @date 2019/8/26 16:22
     */
    package com.nps.utils;
    
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.time.ZoneId;
    import java.util.Date;
    
    public class DateUtils {
        private static final org.slf4j.Logger logger = null;
        private static final java.time.format.DateTimeFormatter yyyyMMddFmt = null;
    
        public DateUtils() {
        }
    
        public static boolean sameDate(java.util.Date d1, java.util.Date d2){
            return d1.equals(d2);
        }
    
        public static java.time.LocalDate getDateByStr(java.lang.String dateStr, java.lang.String fmt) {
            try {
                return dateToLocalDate(new SimpleDateFormat().parse(dateStr+fmt));
            } catch (ParseException e) {
                e.printStackTrace();
            }
            return null;
        }
    
        public static java.time.LocalDate dateToLocalDate(java.util.Date date) {
            return date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
        }
    
        public static java.time.LocalDateTime dateToLocalDateTime(java.util.Date date){
            return date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
        }
    
        public static java.util.Date localDateToDate(java.time.LocalDate localDate){
            return Date.from(localDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
        }
    
        public static java.util.Date localDateTimeToDate(java.time.LocalDateTime localDateTime){
            return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
        }
    
        public static java.lang.String dateToString(java.util.Date date){ return date.toString();}
    
        public static void main(String[] args) {
    
        }
    
    }
    

      

    /*
    * @author XueWeiWei
    * @date 2019/8/26 16:22
    */
    package com.nps.utils;

    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.time.ZoneId;
    import java.util.Date;

    public class DateUtils {
    private static final org.slf4j.Logger logger = null;
    private static final java.time.format.DateTimeFormatter yyyyMMddFmt = null;

    public DateUtils() {
    }

    public static boolean sameDate(java.util.Date d1, java.util.Date d2){
    return d1.equals(d2);
    }

    public static java.time.LocalDate getDateByStr(java.lang.String dateStr, java.lang.String fmt) {
    try {
    return dateToLocalDate(new SimpleDateFormat().parse(dateStr+fmt));
    } catch (ParseException e) {
    e.printStackTrace();
    }
    return null;
    }

    public static java.time.LocalDate dateToLocalDate(java.util.Date date) {
    return date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
    }

    public static java.time.LocalDateTime dateToLocalDateTime(java.util.Date date){
    return date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
    }

    public static java.util.Date localDateToDate(java.time.LocalDate localDate){
    return Date.from(localDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
    }

    public static java.util.Date localDateTimeToDate(java.time.LocalDateTime localDateTime){
    return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
    }

    public static java.lang.String dateToString(java.util.Date date){ return date.toString();}

    public static void main(String[] args) {

    }

    }
  • 相关阅读:
    MongoDB Java 学习笔记 (Java操作MongoDB)
    SQL中CONVERT转化函数的用法
    C# winform滚动字幕
    修改msconfig->引导->高级选项-》最大内存为512M
    把CheckedListBoxControl设置为单选框
    base.AutoScaleMode = AutoScaleMode.Font; 方法“InitializeComponent”内的代码由设计器生成,不应手动修改。请移除任何更改,然后尝试重新打开设计器”。
    winform 上传文件
    C#winform MDI子窗体打开时内容显示不全
    C# 网页信息采集(数据访问)
    RTO & RPO
  • 原文地址:https://www.cnblogs.com/xww115/p/11413802.html
Copyright © 2020-2023  润新知