前臺傳遞date日期參數:2018-07-09,如今須要是要轉換成相似格式 2018-07-09 00:00:00,即把時間部分也初始化。java
轉化思路:經過java工具類 calendar.setTime(date)初始化calendar,而後經過calendar的set方法設置時分秒。最後調用calendar.getTime()方法。工具
完整代碼以下:code
public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINESE); try { Date date = dateFormat.parse("2018-07-09"); calendar.setTime(date); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); Date newDate = calendar.getTime(); } catch (ParseException e) { } }