Android examples for java.util:Date Format
Format Date to String in yyyyMMdd_HHmmss format
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 }