Convert String Date format from yyyy-MM-dd HH:mm to MM-dd HH:mm format - Android java.util

Android examples for java.util:Date Time

Description

Convert String Date format from yyyy-MM-dd HH:mm to MM-dd HH:mm format

Demo Code

import java.text.SimpleDateFormat;
import java.util.Date;

public class Main{

    public static String getStringForDate(String date) {

        SimpleDateFormat formatter = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm");
        SimpleDateFormat f = new SimpleDateFormat("MM-dd HH:mm");
        Date d = new Date();
        try {/*from   w  w  w  . j  a  v  a  2s . c  om*/
            d = formatter.parse(date);
        } catch (Exception e) {
            e.printStackTrace();
        }
        String dateString = f.format(d);
        return dateString;

    }
    public static String getStringForDate(long date) {

        SimpleDateFormat f = new SimpleDateFormat("MM-dd HH:mm");
        Date d = new Date(date);
        String dateString = f.format(d);
        return dateString;

    }

}

Related Tutorials