Date类型转换为String类型
public static String dateToString(Date data, String formatType) {
return new SimpleDateFormat(formatType).format(data);
}
Long类型转换为String类型
public static String longToString(long currentTime, String formatType)
throws ParseException {
Date date = longToDate(currentTime, formatType);
String strTime = dateToString(date, formatType);
return strTime;
}
String类型转换为Date类型
public static Date stringToDate(String strTime, String formatType)
throws ParseException {
SimpleDateFormat formatter = new SimpleDateFormat(formatType);
Date date = null;
date = formatter.parse(strTime);
return date;
}
Long转换为Date类型
public static Date longToDate(long currentTime, String formatType)
throws ParseException {
Date dateOld = new Date(currentTime);
String sDateTime = dateToString(dateOld, formatType);
Date date = stringToDate(sDateTime, formatType);
return date;
}
String类型转换为Long类型
public static long stringToLong(String strTime, String formatType)
throws ParseException {
Date date = stringToDate(strTime, formatType);
if (date == null) {
return 0;
} else {
long currentTime = dateToLong(date);
return currentTime;
}
}
Date类型转换为Long类型
public static long dateToLong(Date date) {
return date.getTime();
}
原文地址