zoukankan      html  css  js  c++  java
  • Java常见知识积累

    1.计算两个日期时间差

    public static String getDatePoor(Date endDate, Date nowDate) {
     
        long nd = 1000 * 24 * 60 * 60;
        long nh = 1000 * 60 * 60;
        long nm = 1000 * 60;
        // long ns = 1000;
        // 获得两个时间的毫秒时间差异
        long diff = endDate.getTime() - nowDate.getTime();
        // 计算差多少天
        long day = diff / nd;
        // 计算差多少小时
        long hour = diff % nd / nh;
        // 计算差多少分钟
        long min = diff % nd % nh / nm;
        // 计算差多少秒//输出结果
        // long sec = diff % nd % nh % nm / ns;
        return day + "天" + hour + "小时" + min + "分钟";
    }

    2.日期转字符串

    public static String DateToStr(Date date) {
          
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String str = format.format(date);
        return str;
    }

    3.字符串转日期

    public static Date StrToDate(String str) {
    
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = null;
        try {
            date = format.parse(str);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }

    4.SQL日期转字符串:
    select to_char(sysdate,'yyyy-MM-dd HH24:mi:ss') from dual;
    SQL字符串转日期:
    select to_date('2005-01-01 13:14:20','yyyy-MM-dd HH24:mi:ss') from dual;

  • 相关阅读:
    keepalived安装
    Nginx学习笔记
    使用xhprof分析php性能
    使用 .bash_profile与.bashrc修改字符集
    Mysql分区简述
    c语言多线程队列读写
    setsockopt 设置 SO_LINGER 选项
    nginx配置rewrite
    使用PHP+ajax打造聊天室应用
    UDP/TCP通信小记
  • 原文地址:https://www.cnblogs.com/wuwuyong/p/14190849.html
Copyright © 2011-2022 走看看