Android Date Format String Create convertFormat(String src, String f1, String f2)

Here you can find the source of convertFormat(String src, String f1, String f2)

Description

convert Format

Declaration

public static String convertFormat(String src, String f1, String f2) 

Method Source Code

//package com.java2s;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static final String VN_DATE_FORMAT = "dd/MM/yyyy";

    public static String convertFormat(String src, String f1, String f2) {
        Date date = stringToDate(src, f1);
        return dateToString(date, f2);
    }//  w  w w. j  a  v  a2s.c  om

    public static java.util.Date stringToDate(String src, String format) {

        try {
            src = src.trim();
            if (format == null)
                format = VN_DATE_FORMAT;
            SimpleDateFormat ts = new SimpleDateFormat(format);

            return ts.parse(src);
        } catch (Exception e) {
            return null;
        }
    }

    public static String dateToString(Date date, String format) {
        if (format == null)
            format = VN_DATE_FORMAT;
        SimpleDateFormat ts = new SimpleDateFormat(format);
        return ts.format(date);
    }

    public static java.util.Date parse(String src) {
        try {
            return DateFormat.getDateInstance().parse(src);
        } catch (ParseException e) {
            return DateFormat.getInstance().getCalendar().getTime();
        }
    }
}

Related

  1. getFormat(String pattern)
  2. getDateFormatSymbols(Locale locale)
  3. changeFormat(String gmtString, String orgFormat, String format)
  4. dateFormatToString(int date, Context context)
  5. getGMTDateFormat()
  6. getSimpleDateFormat()
  7. getSimpleDateFormatter()