Convert date value from one format to another format - Android java.util

Android examples for java.util:Date Convert

Description

Convert date value from one format to another format

Demo Code

import android.annotation.SuppressLint;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

public class Main{


    public static String string2String(String str, String format,
            String secondFormat) {
        try {//  w w  w.j a  va  2  s  . c o  m
            return date2String(new SimpleDateFormat(format).parse(str)
                    .getTime(), secondFormat);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return new Date().toString();
    }

}

Related Tutorials