java 时间日期转换

    //时间转换,在原有时间后面默认添加“ 23:59:59”
    public Date dateModify(Date oldTime) throws ParseException{
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat sdfNew = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //对传入的Date类型的数据进行格式化
        String oldT= sdf.format(oldTime);
        //对格式化后的数据进行字符串的拼接
        String newT = oldT + " 23:59:59";
        //将拼接后的字符串时间转换为Date类型并返回
        return sdfNew.parse(newT);
    }
    将传入的Date格式的数据进行格式化并添加默认结束时间,再次转换为Date格式后返回

猜你喜欢

转载自blog.csdn.net/csdn565973850/article/details/73838651