Format Date to String in yyyyMMdd_HHmmss format - Android java.util

Android examples for java.util:Date Format

Description

Format Date to String in yyyyMMdd_HHmmss format

Demo Code

import android.annotation.SuppressLint;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main{

    @SuppressLint("SimpleDateFormat")
    public static String getDateFormatString(Date date) {
        if (date == null)
            date = new Date();
        String formatStr = new String();
        SimpleDateFormat matter = new SimpleDateFormat("yyyyMMdd_HHmmss");
        formatStr = matter.format(date);
        return formatStr;
    }//from   ww  w . jav  a2  s.  c  om

}

Related Tutorials