Android Utililty Methods Date Format String Create

List of utility methods to do Date Format String Create


The list of methods to do Date Format String Create are organized into topic(s).


DateFormatgetFormat(String pattern)
get Format
DateFormat format = DFS.get(pattern);
if (format == null) {
    format = new SimpleDateFormat(pattern);
    DFS.put(pattern, format);
return format;
DateFormatSymbolsgetDateFormatSymbols(Locale locale)
Gets the DateFormatSymbols based on the given locale.
try {
    Method method = DateFormatSymbols.class.getMethod(
            "getInstance", new Class[] { Locale.class });
    return (DateFormatSymbols) method.invoke(null,
            new Object[] { locale });
} catch (Exception ex) {
    return new DateFormatSymbols(locale);
StringchangeFormat(String gmtString, String orgFormat, String format)
change Format
final Date date = getDateTimeFromString(gmtString, orgFormat);
SimpleDateFormat formatter = new SimpleDateFormat(format);
return formatter.format(date);
StringconvertFormat(String src, String f1, String f2)
convert Format
Date date = stringToDate(src, f1);
return dateToString(date, f2);
StringdateFormatToString(int date, Context context)
date Format To String
String dateString = "";
long currentTime = System.currentTimeMillis() / 1000;
int dateTime = (int) (currentTime - date) / 60;
if (date == 0) {
    return dateString;
if (dateTime > 4320) {
    dateString = getDateString(date);
get GMT Date Format
DateFormat dateFormat = new SimpleDateFormat(
        "EEE MMM d HH:mm:ss z yyyy", Locale.ENGLISH);
return dateFormat;
get Simple Date Format
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
get Simple Date Formatter
if (sDateFormat == null) {
    sDateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
return sDateFormat;
DategetDateByFormat(String strDate, String format)
get Date By Format
SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format);
Date date = null;
try {
    date = mSimpleDateFormat.parse(strDate);
} catch (ParseException e) {
return date;
StringgetStringByFormat(String strDate, String format)
get String By Format
String mDateTime = null;
try {
    Calendar c = new GregorianCalendar();
    SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(
    SimpleDateFormat mSimpleDateFormat2 = new SimpleDateFormat(