Here you can find the source of currentDateStr(String format)
public static String currentDateStr(String format)
//package com.java2s; //License from project: Open Source License import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { public static String currentDateStr(String format) { return toString(format, now()); }// w w w .ja va 2s . c o m public static String toString(String format, Date date) { if (format == null || format.isEmpty()) { return format; } if (date == null) { return null; } DateFormat dateFormat = new SimpleDateFormat(format); return dateFormat.format(date); } public static String toString(Date date, String format) { if (format == null || format.isEmpty()) { return format; } if (date == null) { return null; } DateFormat dateFormat = new SimpleDateFormat(format); return dateFormat.format(date); } public static Date now() { Calendar cal = Calendar.getInstance(); return cal.getTime(); } }