Get a Date object with only [year month day]

Java code   Favorite code
  1. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");  
  2.   String sDate = simpleDateFormat.format(new Date());  
  3.   Date date = null;  
  4.   try {  
  5.    date = simpleDateFormat.parse(sDate);  
  6.   } catch (ParseException e) {  
  7.    log.debug("Get Current Date Exception [by ninja.hzw]"+e);  
  8.   }  

 

Note here that the MM of the string "yyyy-MM-dd" passed in SimpleDateFormat must be uppercase, otherwise it will be considered that the mm of hours and minutes will not achieve the expected effect.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324933309&siteId=291194637