Java Utililty Methods yyyy

List of utility methods to do yyyy

Description

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

Method

StringformatDate(final Date date, final String defaultValue)
format Date
if (date == null) {
    return defaultValue;
return dateFormat.format(date);
StringformatDate(String date)
Format date.
String invDt1[] = date.toString().split("-");
String invDt = invDt1[2] + "-" + invDt1[1] + "-" + invDt1[0];
System.out.println("<<<<date>>>> " + invDt);
return invDt;
DateformatDate(String date)
format Date
DateFormat myDateFormat = new SimpleDateFormat(DATE_FORMAT);
return myDateFormat.parse(date);
DateformatDate(String date)
format Date
try {
    return DEFAUALT_DATE_FORMAT.parse(date);
} catch (ParseException e) {
    e.printStackTrace();
return null;
StringformatDate(String inputDate)
format Date
SimpleDateFormat DATE_FORMAT = new SimpleDateFormat(inputDateFormat);
Date d = DATE_FORMAT.parse(inputDate);
DATE_FORMAT.applyPattern(outputDateFormat);
return DATE_FORMAT.format(d);
StringformatDate2DateStr()
Format the current date time to "yyyy-MM-dd" format string.
return formatDate2DateStr(new Date());
StringformatDate2DateStr()
Format the current date time to "yyyy-MM-dd" format string.
return formatDate2DateStr(new Date());
StringformatDate2ShortStr(Date date)
Format the given date time to "yyyyMMdd" format string.
SimpleDateFormat s = new SimpleDateFormat("yyyyMMdd");
return s.format(date);
StringformatDate2Str(Date date)
format Date Str
return (new SimpleDateFormat("yyyy-MM-dd").format(date));
StringformatDateAsShortDateLocalTime(Date moonDate, TimeZone tz)
Useful date-to-string formatting which I found myself using a lot
DateFormat sdf = SimpleDateFormat.getDateInstance(SHORT);
sdf.setTimeZone(tz);
((SimpleDateFormat) sdf).applyPattern("yyyy-MM-dd");
return sdf.format(moonDate);