Java Utililty Methods Date Format Pattern

List of utility methods to do Date Format Pattern

Description

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

Method

StringgetFormattedValue(Object customFieldValue)
Get a formatted value as pattern "dd/MMM/yy" if the value is instance of Date
String cfValue = "";
if (customFieldValue instanceof Date) {
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MMM/yy");
    Date date = (Date) customFieldValue;
    cfValue = sdf.format(date).toString();
} else {
    cfValue = customFieldValue.toString();
return cfValue;
DateFormatgetFormatter()
get Formatter
return formatter;
DateFormatgetFormatter()
Retrieves the DateFormat for the current Thread
DateFormat formatter = FORMATTER.get();
if (formatter == null) {
    formatter = createIsoDateFormatter();
    FORMATTER.set(formatter);
return formatter;
ThreadLocalgetFormatter(final String pattern)
get Formatter
if (!formatters.containsKey(pattern)) {
    formatters.put(pattern, new ThreadLocal<SimpleDateFormat>() {
        @Override
        protected SimpleDateFormat initialValue() {
            return new SimpleDateFormat(pattern);
    });
return formatters.get(pattern);
SimpleDateFormatgetFormatter(String pattern)
get Formatter
SimpleDateFormat sdf = null;
if (formatters.containsKey(pattern)) {
    sdf = formatters.get(pattern);
} else {
    sdf = new SimpleDateFormat(pattern);
    formatters.put(pattern, sdf);
return sdf;
...
SimpleDateFormat[]getFormatters()
_more_
if (sdfs == null) {
    SimpleDateFormat[] tmp = new SimpleDateFormat[formats.length];
    for (int i = 0; i < formats.length; i++) {
        tmp[i] = new SimpleDateFormat(formats[i]);
    sdfs = tmp;
return sdfs;
...
SimpleDateFormatgetFormatToSecsForFilename()
Returns a date format to the resolution of seconds, for use in filenames:

yyyy-MM-dd_HH-mm-ss

return new SimpleDateFormat(FORMAT_TO_SECS_FOR_FILE);
DateFormatgetHeaderFormat()
get Header Format
DateFormat format = headerFormat.get();
if (format == null) {
    format = new SimpleDateFormat(HEADER_FORMAT, Locale.ENGLISH);
    format.setTimeZone(TimeZone.getTimeZone("UTC"));
    headerFormat.set(format);
return format;
SimpleDateFormatgetLenientFormat(String format)
Return a simple date formatter that is lenient.
SimpleDateFormat tformatter = new SimpleDateFormat(format);
tformatter.setLenient(false);
return tformatter;
StringgetMM()
get MM
SimpleDateFormat formatterMM = new SimpleDateFormat("MM");
return formatterMM.format(Calendar.getInstance().getTime());