我是靠谱客的博主 清新海燕,这篇文章主要介绍java DateUtils 常用工具类,现在分享给大家,希望可以做个参考。

java DateUtils 常用工具类

   /**
     * 得到当前时间
     *
     * @return
     */
    public static Date now() {
        return new Date();
    }

    public static Long getNowStr() {
        return new Date().getTime();
    }
/**
     * 时间格式化
     *
     * @param date
     * @return
     */
    public static final String simpleFormat(Date date) {
        if (date != null) {
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:MM:ss");
            String strDate = df.format(date);
            return strDate;
        }
        return null;
    }
/**
     * 得到两个时间的差值
     *
     * @param dBefor
     * @param dAfter
     * @return
     */
    public static final long getDateBetween(Date dBefor, Date dAfter) {
        long lBefor = 0L;
        long lAfter = 0L;
        long lRtn = 0L;
        lBefor = dBefor.getTime();
        lAfter = dAfter.getTime();
        lRtn = lAfter - lBefor;
        return lRtn;
    }
        /**
         * 在时间上面添加几天
         * @param date
         * @return
         */
         public static Date addDay(Date date, int days) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.add(6, days);
        return c.getTime();
    }

最后

以上就是清新海燕最近收集整理的关于java DateUtils 常用工具类的全部内容,更多相关java内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(105)

评论列表共有 0 条评论

立即
投稿
返回
顶部