Java Utililty Methods Now

List of utility methods to do Now

Description

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

Method

StringnowStr()
Return a string representing the current time.
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
return format.format(new Date());
StringnowString(String pattern)
now String
return getDateFormat(pattern).format(new Date());
StringnowString(String pattern)
Return the current date in the specified format
Calendar cal = Calendar.getInstance();
Date currDate = cal.getTime();
return format(currDate, pattern);
StringnowTime(String formartStr)
now Time
String strDate = null;
if ((formartStr != null) && (!"".equals(formartStr))) {
    SimpleDateFormat sdf = new SimpleDateFormat(formartStr);
    strDate = sdf.format(new Date());
return strDate;
StringnowTime(String format)
now Time
return new SimpleDateFormat(format).format(new Date());
StringprintNow()
print Now
return toString(currentDate());
StringstringDate(Date now)
string Date
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return simpleDateFormat.format(now);
StringsubNow()
sub Now
return getNow().substring(0, 10);
StringtoStr2(Date now)
to Str
String s = "";
try {
    s = dateFomat2.format(now);
} catch (Exception e) {
    e.printStackTrace();
return s;
StringtoString(Date now)
to String
SimpleDateFormat formatTime = new SimpleDateFormat(PATNER_DEFAULT);
if (now == null)
    return "";
return formatTime.format(now);