Here you can find the source of string2DateTimeByAutoZero(String stringDate)
public static final Date string2DateTimeByAutoZero(String stringDate) throws ParseException
//package com.java2s; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; public class Main { public static final String datetimeFormat = "yyyy-MM-dd HH:mm:ss"; public static final Date string2DateTimeByAutoZero(String stringDate) throws ParseException { if (stringDate == null) { return null; }//from w w w. j av a 2s . co m if (stringDate.length() == 11) stringDate = stringDate + "00:00:00"; else if (stringDate.length() == 13) stringDate = stringDate + ":00:00"; else if (stringDate.length() == 16) stringDate = stringDate + ":00"; else if (stringDate.length() == 10) stringDate = stringDate + " 00:00:00"; return getFormat(datetimeFormat).parse(stringDate); } public static final DateFormat getFormat(String format) { return new SimpleDateFormat(format); } }