1 date format example:
public static final String DATE_FORMAT_1 = "M/d/yyyy";
public static final String DATE_FORMAT_2 = "MM/dd/yyyy";
public static final String DATE_FORMAT_3 = "M/d/yyyy hh:mm:ss a";
public static final String DATE_FORMAT_4 = "yyyy-MM-dd";
public static final String DATE_FORMAT_5 = "EEEEE, MMM.dd";
public static final String DATE_FORMAT_LONG = "MMMMM dd, yyyy EEEEE";
public static final String DATE_FORMAT_SHORT = "MMM dd, yyyy EEE";
public static final String DATE_FORMAT_HOUR_TWENTY_FOUR = "MM/dd/yyyy HH:mm:ss";
public static final String DATE_FORMAT_HOUR_TWELVE = "MM/dd/yyyy hh:mm:ss a";
public static final String DATE_FORMAT_COUPON = "yyyy-MM-dd'T'HH:mm:ss";
// #8601
public static final String DATE_FORMAT_PV_EVENT = "yyyyMMdd.HHmmss.SSSZZ";
2. format a date type
/**
* format date
*
* @param format
* @param date
* @return formatted date string
*/
public static String formatDate(String format, Date date) {
return DateFormat.format(format, date).toString();
}
3. format a date string type
/**
*
* @param date
* @param formatIn
* @param formatOut
* @return
*/
public static String changeDateFormate(String date, String formatIn, String formatOut) {
SimpleDateFormat inFormat = new SimpleDateFormat(formatIn, Locale.US);
SimpleDateFormat outFormat = new SimpleDateFormat(formatOut, Locale.US);
try {
Date mDate = inFormat.parse(date);
return outFormat.format(mDate);
} catch (ParseException e) {
e.printStackTrace();
}
return date;
}