获得只有 [年 月 日] 的Date 对象

时间:2023-03-09 15:39:18
获得只有 [年 月 日] 的Date 对象
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
String sDate = simpleDateFormat.format(new Date());
Date date = null;
try {
date = simpleDateFormat.parse(sDate);
} catch (ParseException e) {
log.debug("Get Current Date Exception [by ninja.hzw]"+e);
}

这里注意  SimpleDateFormat 里传的字符串“yyyy-MM-dd”  的 MM 必须为大写,否则会被认为成时分钟的mm 不会达到预期效果。