convert Date Format - Android java.util

Android examples for java.util:Date Convert

Description

convert Date Format

Demo Code

import android.content.Context;
import android.provider.Settings;
import android.telephony.PhoneNumberUtils;
import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Random;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{

    public static String convertDateFormat(String myTime, String dateIn,
            String dateOut) {/* w  w  w  .ja  v  a  2s.  c om*/
        SimpleDateFormat dateFormatIn = new SimpleDateFormat(dateIn);
        SimpleDateFormat dateFormatOut = new SimpleDateFormat(dateOut);
        Date myDate = null;
        try {
            myDate = dateFormatIn.parse(myTime);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        String finalDate = dateFormatOut.format(myDate);
        return finalDate;
    }

}

Related Tutorials