Here you can find the source of nowString(String pattern)
Parameter | Description |
---|---|
strFormat | a parameter |
public static String nowString(String pattern)
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { /**// ww w.j a v a 2s .c o m * yyyy-MM-dd */ public static final String DATE_PATTERN_DEFAULT = "yyyy-MM-dd"; public static String nowString() { Calendar cal = Calendar.getInstance(); Date currDate = cal.getTime(); return formatDate(currDate); } /** * Return the current date in the specified format * * @param strFormat * @return */ public static String nowString(String pattern) { Calendar cal = Calendar.getInstance(); Date currDate = cal.getTime(); return format(currDate, pattern); } public static String formatDate(Date d) { return format(d, DATE_PATTERN_DEFAULT); } public static String format(Date d, String pattern) { if (d == null) return null; SimpleDateFormat dateFromat = new SimpleDateFormat(pattern); return dateFromat.format(d); } }