Java Utililty Methods Date Now

List of utility methods to do Date Now

Description

The list of methods to do Date Now are organized into topic(s).

Method

StringgetCurrentDate(String format)
get Current Date
if (format == null || format.isEmpty())
    format = "yyyy.MM.dd'-'HH:mm:ss";
java.text.DateFormat dateFormat = new java.text.SimpleDateFormat(format);
java.util.Date date = new java.util.Date();
String currDate = dateFormat.format(date);
return currDate;
StringgetCurrentDate(String formatStr)
get Current Date
if ("mm/dd/yyyy".equals(formatStr)) {
    formatStr = DISPLAY_DATE_FORMAT;
SimpleDateFormat formatter = new SimpleDateFormat(formatStr);
Date currentDate = new Date();
return formatter.format(currentDate);
StringgetCurrentDate(String pattern)
get Current Date
SimpleDateFormat datePattern = null;
if (null == pattern || "".equals(pattern)) {
    datePattern = new SimpleDateFormat("yyyyMMdd");
} else {
    datePattern = new SimpleDateFormat(pattern);
return datePattern.format(new Date());
StringgetCurrentDate(String pattern)
get Current Date
String result;
SimpleDateFormat formatter = new SimpleDateFormat(pattern);
result = formatter.format(new Date());
return result;
StringgetCurrentDate(String pattern)
Formats the current date into a string according to a specified pattern.
return formatDate(pattern, new Date());
StringgetCurrentDate(String pattern, Locale locale)
get Current Date
return getDate(new Date(), pattern, locale);
StringgetCurrentDate2(String format)
get Current Date
Date dateNow = Calendar.getInstance(new SimpleTimeZone(9 * 60 * 60 * 1000, "KST")).getTime();
SimpleDateFormat formatter = new SimpleDateFormat(format, Locale.getDefault());
return formatter.format(dateNow);
StringgetCurrentDate_String()
get Current Dat String
return dateToString(now(), DF_YMD);
StringgetCurrentDate_YYYY_MM_DD()
Here get the current date in format 'YYYY-MM-DD'
Calendar cal = Calendar.getInstance(TimeZone.getDefault());
final String dateFormat = "yyyy-MM-dd";
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(dateFormat);
sdf.setTimeZone(TimeZone.getDefault());
return sdf.format(cal.getTime());
StringgetCurrentDateAllformated()
get Current Date Allformated
Locale loc = new Locale("zh", "CN");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", loc);
return sdf.format(new Date());