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(Date date, String outputPattern)
format Date
if (date == null) {
    return null;
SimpleDateFormat sdf = new SimpleDateFormat(outputPattern);
return sdf.format(date);
StringformatDate(Date date, String pattern)
format Date
LOCK.lock();
try {
    DateFormat fmt = new SimpleDateFormat(pattern);
    return fmt.format(date);
} catch (Exception e) {
    e.printStackTrace();
    return null;
} finally {
...
StringformatDate(Date date, String pattern)
format date with the given pattern.
SimpleDateFormat format = new SimpleDateFormat(pattern);
return format.format(date);
StringformatDate(Date date, String pattern)
format Date
SimpleDateFormat format = new SimpleDateFormat(pattern);
return format.format(date);
StringformatDate(Date date, String pattern)
format Date
if (pattern == null || pattern.equals("") || pattern.equals("null")) {
    pattern = "yyyy-MM-dd";
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
return sdf.format(date);
StringFormatDate(Date date, String sf)
Format Date
if (date == null)
    return "";
SimpleDateFormat dateformat = new SimpleDateFormat(sf);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
if (date.getHours() == 0)
    return sdf.format(date);
else
    return dateformat.format(date);
...
StringformatDate(Date date, TimeZone timeZone)
format Date
return TIMEZONE_DATE_FORMATS.get().computeIfAbsent(timeZone, aTimeZone -> {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    sdf.setTimeZone(aTimeZone);
    return sdf;
}).format(date);
StringformatDate(Date inputDate, String formatPattern)
Formats the date as specified in the target pattern.
String returnValue = null;
if ((inputDate != null) && (formatPattern != null)) {
    SimpleDateFormat targetFormat = new SimpleDateFormat(formatPattern);
    returnValue = targetFormat.format(inputDate);
return returnValue;
StringformatDate(Date unformattedDate, String format)
Formats a give date with the supplied format
String formattedDate = "";
try {
    DateFormat df = DateFormat.getInstance();
    SimpleDateFormat sf = (SimpleDateFormat) df;
    sf.applyPattern(format);
    formattedDate = df.format(unformattedDate);
} catch (RuntimeException e) {
return formattedDate;
StringformatDate(DateTime aDateTime)
format Date
if (aDateTime == null) {
    return null;
SimpleDateFormat theFormat = new SimpleDateFormat(XML_DATE_FORMAT);
theFormat.setTimeZone(Calendar.getInstance().getTimeZone());
return theFormat.format(aDateTime.toDate());