// DATE type is converted to a String // formatType format of MM-dd HH-yyyy: mm: ss // When Day HH yyyy dd month in MM mm minutes ss seconds // the Data Type of a Date time public static String dateToString (a Date Data, String formatType) { return new new the SimpleDateFormat (formatType) .format (Data); } // Long type to a String // Long type currentTime time to convert // String to convert the type of time format formatType public static longToString String ( Long currentTime, String formatType) throws a ParseException { a Date DATE = longToDate (currentTime, formatType); //Date type turn into long type String strTime = dateToString (date, formatType); // date type turn into String return strTime; } // String type to date type // String to convert type strTime time, formatType to convert format mM-dd HH-yyyy: mm: ss // yyyy Year mM month dd day // when HH mm minutes ss seconds, // strTime time format must be the same as formatType time format public static a date stringToDate (String strTime, formatType String) throws a ParseException { the SimpleDateFormat Formatter = new new the SimpleDateFormat (formatType); a Date DATE = null ; DATE =formatter.parse (strTime); return DATE; } // Long to type Date // Long type currentTime time to convert // formatType time format to convert the MM-dd-HH YYYY: mm: SS // YYYY Year when mM month dd day HH mm ss a public static a date longToDate ( long currentTime, String formatType) throws a ParseException { a date dateOld = new new a date (currentTime); // the type of milliseconds long life time of a date type String sDateTime = dateToString (dateOld, formatType); // the type of date time into String a Date date = stringToDate (sDateTime, formatType); //The type to type Date String return DATE; } // String type to type long // String type of time to convert strTime // formatType time format // time format and the strTime must formatType same public static long stringToLong (strTime String, String formatType) throws a ParseException { a Date date = stringToDate (strTime, formatType); // String type turn into a date type IF (date == null ) { return 0 ; } the else { Long currentTime = dateToLong (date) ; //date type turn as a long return currentTime; } } // date type to type long // date type of date time to convert public static long dateToLong (a Date date) { return date.getTime (); }