Example usage for org.apache.commons.lang3.time FastDateFormat getInstance

List of usage examples for org.apache.commons.lang3.time FastDateFormat getInstance

Introduction

In this page you can find the example usage for org.apache.commons.lang3.time FastDateFormat getInstance.

Prototype

public static FastDateFormat getInstance(final String pattern, final TimeZone timeZone, final Locale locale) 

Source Link

Document

Gets a formatter instance using the specified pattern, time zone and locale.

Usage

From source file:com.derbysoft.common.log4j.DailyRollingFileAppender.java

public void activateOptions() {
    super.activateOptions();
    if (datePattern != null && fileName != null) {
        now.setTime(System.currentTimeMillis());
        sdf = FastDateFormat.getInstance(datePattern, timeZone, Locale.getDefault());
        int type = computeCheckPeriod();
        printPeriodicity(type);//  w  ww  . j av a2  s .c  om
        rc.setType(type);
        File file = new File(fileName);
        scheduledFilename = fileName + sdf.format(new Date(file.lastModified()));

    } else {
        LogLog.error("Either File or DatePattern options are not set for appender [" + name + "].");
    }
}

From source file:org.apache.openmeetings.service.calendar.caldav.IcalUtils.java

/**
 * Adapted from DateUtils to support Timezones, and parse ical dates into {@link java.util.Date}.
 * Note: Replace FastDateFormat to java.time, when shifting to Java 8 or higher.
 *
 * @param str      Date representation in String.
 * @param patterns Patterns to parse the date against
 * @param _timeZone Timezone of the Date.
 * @return <code>java.util.Date</code> representation of string or
 * <code>null</code> if the Date could not be parsed.
 *///w w w .j a  v a  2  s.  com
public Date parseDate(String str, String[] patterns, TimeZone _timeZone) {
    FastDateFormat parser;
    Locale locale = WebSession.get().getLocale();

    TimeZone timeZone = str.endsWith("Z") ? TimeZone.getTimeZone("UTC") : _timeZone;

    ParsePosition pos = new ParsePosition(0);
    for (String pattern : patterns) {
        parser = FastDateFormat.getInstance(pattern, timeZone, locale);
        pos.setIndex(0);
        Date date = parser.parse(str, pos);
        if (date != null && pos.getIndex() == str.length()) {
            return date;
        }
    }
    log.error("Unable to parse the date: " + str + " at " + -1);
    return null;
}