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

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

Introduction

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

Prototype

@Override
public String format(final Calendar calendar) 

Source Link

Document

Formats a Calendar object.

Usage

From source file:com.hp.hpl.jena.sparql.util.Utils.java

public static String nowAsString(FastDateFormat dateFormat) {
    return dateFormat.format(new Date());
}

From source file:com.hp.hpl.jena.sparql.util.Utils.java

public static String nowAsString(String formatString) {
    FastDateFormat df = FastDateFormat.getInstance(formatString);
    return df.format(new Date());
}

From source file:com.gargoylesoftware.htmlunit.javascript.host.DateCustom.java

/**
 * Converts a date to a string, returning the "time" portion using the current locale's conventions.
 * @param context the JavaScript context
 * @param thisObj the scriptable//from  w  w w.  j av a  2s.  co  m
 * @param args the arguments passed into the method
 * @param function the function
 * @return converted string
 */
public static String toLocaleTimeString(final Context context, final Scriptable thisObj, final Object[] args,
        final Function function) {
    final String formatString;
    final BrowserVersion browserVersion = ((Window) thisObj.getParentScope()).getWebWindow().getWebClient()
            .getBrowserVersion();

    if (browserVersion.hasFeature(JS_DATE_LOCALE_TIME_WITH_SPECIAL_CHARS)) {
        // [U+200E] -> Unicode Character 'LEFT-TO-RIGHT MARK'
        formatString = "\u200EHH\u200E:\u200Emm\u200E:\u200Ess";
    } else {
        formatString = "HH:mm:ss";
    }
    final FastDateFormat format = FastDateFormat.getInstance(formatString, getLocale(thisObj));
    return format.format(getDateValue(thisObj));
}

From source file:com.gargoylesoftware.htmlunit.javascript.host.DateCustom.java

/**
 * Converts a date to a string, returning the "date" portion using the operating system's locale's conventions.
 * @param context the JavaScript context
 * @param thisObj the scriptable/* w  w w  .  j  av  a  2s  .  co m*/
 * @param args the arguments passed into the method
 * @param function the function
 * @return converted string
 */
public static String toLocaleDateString(final Context context, final Scriptable thisObj, final Object[] args,
        final Function function) {
    final String formatString;
    final BrowserVersion browserVersion = ((Window) thisObj.getParentScope()).getBrowserVersion();

    if (browserVersion.hasFeature(JS_DATE_LOCALE_DATE_SHORT_WITH_SPECIAL_CHARS)) {
        // [U+200E] -> Unicode Character 'LEFT-TO-RIGHT MARK'
        formatString = "\u200Edd\u200E.\u200EMM\u200E.\u200Eyyyy";
    } else if (browserVersion.hasFeature(JS_DATE_LOCALE_DATE_SHORT)) {
        formatString = "d.M.yyyy";
    } else {
        formatString = "EEEE, MMMM dd, yyyy";
    }
    final FastDateFormat format = FastDateFormat.getInstance(formatString, getLocale(thisObj));
    return format.format(getDateValue(thisObj));
}

From source file:com.baifendian.swordfish.common.utils.DateUtils.java

/**
 * ??//from ww  w . j  a v a  2 s.  co  m
 *
 * @param date
 * @param formatString
 * @return
 */
public static String format(Date date, String formatString) {
    if (date == null) {
        return StringUtils.EMPTY;
    }

    FastDateFormat format = FastDateFormat.getInstance(formatString);
    return format.format(date);
}

From source file:com.hp.hpl.jena.sparql.util.Utils.java

private static String calendarToXSDString(Calendar cal, FastDateFormat fmt) {
    // c.f. Constructor on Jena's XSDDateTime
    // Only issue is that it looses the timezone through (Xerces)
    // normalizing to UTC.
    Date date = cal.getTime();/*from  w w  w  .  j a  va2 s . co  m*/
    String lex = fmt.format(date);
    lex = lex + calcTimezone(cal);
    return lex;
}

From source file:com.epam.parso.impl.CSVDataWriterImpl.java

/**
 * The function to convert a date into a string according to the format used.
 *
 * @param currentDate the date to convert.
 * @param format      the string with the format that must belong to the set of
 *                    {@link CSVDataWriterImpl#DATE_OUTPUT_FORMAT_STRINGS} mapping keys.
 * @return the string that corresponds to the date in the format used.
 *///from  w  w  w  . j  ava  2  s .c o m
protected static String convertDateElementToString(Date currentDate, String format) {
    String valueToPrint = "";
    FastDateFormat dateFormat = FastDateFormat.getInstance(DATE_OUTPUT_FORMAT_STRINGS.get(format),
            TimeZone.getTimeZone("UTC"));
    if (currentDate.getTime() != 0) {
        valueToPrint = dateFormat.format(currentDate.getTime());
    }
    return valueToPrint;
}

From source file:mServer.tool.MserverLog.java

public static void printEndeMeldung() {
    if (fehlerListe.isEmpty()) {
        systemMeldung("###########################################################");
        systemMeldung(" Keine Fehler :)");
        systemMeldung("###########################################################");
    } else {//  w  w w  .  j  a  v a2s.c  o m
        // Fehler ausgeben
        int i_1;
        int i_2;
        for (int i = 1; i < fehlerListe.size(); ++i) {
            for (int k = i; k > 0; --k) {
                i_1 = fehlerListe.get(k - 1)[1];
                i_2 = fehlerListe.get(k)[1];
                // if (str1.compareToIgnoreCase(str2) > 0) {
                if (i_1 < i_2) {
                    fehlerListe.add(k - 1, fehlerListe.remove(k));
                } else {
                    break;
                }
            }
        }
        systemMeldung("###########################################################");
        for (Integer[] integers : fehlerListe) {
            if (integers[0] < 0) {
                systemMeldung(" Fehlernummer: " + integers[0] + " Anzahl: " + integers[1]);
            } else {
                systemMeldung(" Fehlernummer:  " + integers[0] + " Anzahl: " + integers[1]);
            }
        }
        systemMeldung("###########################################################");
    }
    // Laufzeit ausgeben
    final Date stopZeit = new Date(System.currentTimeMillis());
    final FastDateFormat sdf = FastDateFormat.getInstance("dd.MM.yyyy HH:mm:ss");
    final int minuten = Math.round((stopZeit.getTime() - startZeit.getTime()) / (1000 * 60));

    systemMeldung("");
    systemMeldung("");
    systemMeldung("###########################################################");
    systemMeldung("   --> Beginn: " + sdf.format(startZeit));
    systemMeldung("   --> Fertig: " + sdf.format(stopZeit));
    systemMeldung("   --> Dauer[Min]: " + (minuten == 0 ? "<1" : minuten));
    systemMeldung("###########################################################");
    systemMeldung("");
    systemMeldung("   und Tschuess");
    systemMeldung("");
    systemMeldung("");
    systemMeldung("###########################################################");
}

From source file:com.github.snowdream.android.util.Log.java

/**
 * set the log file path/*from   w w  w .  ja  v a  2  s .c  o  m*/
 * <p/>
 * The log file path will be: logDirPath + logFileBaseName + Formated time +logFileSuffix
 *
 * @param logDirPath      the log file dir path,such as "/mnt/sdcard/snowdream/log"
 * @param logFileBaseName the log file base file name,such as "log"
 * @param logFileSuffix   the log file suffix,such as "log"
 */
public static void setPath(String logDirPath, String logFileBaseName, String logFileSuffix) {
    if (!TextUtils.isEmpty(logDirPath)) {
        Log.logDirPath = logDirPath;
    }

    if (!TextUtils.isEmpty(logFileBaseName)) {
        Log.logFileBaseName = logFileBaseName;
    }

    if (!TextUtils.isEmpty(logFileSuffix)) {
        Log.logFileSuffix = logFileSuffix;
    }

    Date myDate = new Date();
    FastDateFormat fdf = FastDateFormat.getInstance("yyyy-MM-dd-HH-mm-ss");
    String myDateString = fdf.format(myDate);

    StringBuffer buffer = new StringBuffer();
    buffer.append(logDirPath);
    if (!logDirPath.endsWith("/")) {
        buffer.append("/");
    }
    buffer.append(logFileBaseName);
    buffer.append("-");
    buffer.append(myDateString);
    buffer.append(".");
    buffer.append(logFileSuffix);

    setPath(buffer.toString());
}

From source file:com.coolstore.common.SLog.java

/**
 * set the log file path/* w w w .j ava 2  s .  c  o m*/
 * <p/>
 * The log file path will be: logDirPath + logFileBaseName + Formated time +logFileSuffix
 *
 * @param logDirPath      the log file dir path,such as "/mnt/sdcard/snowdream/log"
 * @param logFileBaseName the log file base file name,such as "log"
 * @param logFileSuffix   the log file suffix,such as "log"
 */
public static void setPath(String logDirPath, String logFileBaseName, String logFileSuffix) {
    if (!TextUtils.isEmpty(logDirPath)) {
        SLog.logDirPath = logDirPath;
    }

    if (!TextUtils.isEmpty(logFileBaseName)) {
        SLog.logFileBaseName = logFileBaseName;
    }

    if (!TextUtils.isEmpty(logFileSuffix)) {
        SLog.logFileSuffix = logFileSuffix;
    }

    Date myDate = new Date();
    FastDateFormat fdf = FastDateFormat.getInstance("yyyy-MM-dd-HH-mm-ss");
    String myDateString = fdf.format(myDate);

    StringBuffer buffer = new StringBuffer();
    buffer.append(logDirPath);
    if (!logDirPath.endsWith("/")) {
        buffer.append("/");
    }
    buffer.append(logFileBaseName);
    buffer.append("-");
    buffer.append(myDateString);
    buffer.append(".");
    buffer.append(logFileSuffix);

    setPath(buffer.toString());
}