获得只有 [年 月 日] 的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 不会达到预期效果。

posted @ 2017-07-08 15:32  Rainyn  阅读(897)  评论(1)    收藏  举报