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

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

Introduction

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

Prototype

public static String format(final Calendar calendar, final String pattern) 

Source Link

Document

Formats a calendar into a specific pattern.

Usage

From source file:flexjson.transformer.BasicDateTransformer.java

public void transform(Object object) {
    if (object != null) {
        getContext().write(//from  w w  w . j  a  v a2 s  .co m
                "\"" + String.valueOf(DateFormatUtils.format((Date) object, "yyyy-MM-dd HH:mm:ss")) + "\"");
    } else {
        getContext().write("null");
    }
}

From source file:com.willydupreez.examples.features.TimedConsoleGreetingRouteBuilder.java

@Override
public void configure() throws Exception {

    String greeting = "Hello @ " + DateFormatUtils.format(new Date(), "yyyy-MM-dd'T'HH:mm:ss");

    from("timer://greeting-timer?period=1000").setBody(constant(greeting)).to("stream:out");
}

From source file:at.bitfire.davdroid.log.PlainTextFormatter.java

@Override
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
public String format(LogRecord r) {
    StringBuilder builder = new StringBuilder();

    if (!logcat)//from  ww w  .j  av  a  2  s  .  c  o  m
        builder.append(DateFormatUtils.format(r.getMillis(), "yyyy-MM-dd HH:mm:ss")).append(" ")
                .append(r.getThreadID()).append(" ");

    builder.append(String.format("[%s] %s", shortClassName(r.getSourceClassName()), r.getMessage()));

    if (r.getThrown() != null)
        builder.append("\nEXCEPTION ").append(ExceptionUtils.getStackTrace(r.getThrown()));

    if (r.getParameters() != null) {
        int idx = 1;
        for (Object param : r.getParameters())
            builder.append("\n\tPARAMETER #").append(idx++).append(" = ").append(param);
    }

    if (!logcat)
        builder.append("\n");

    return builder.toString();
}

From source file:com.daphne.es.maintain.editor.web.controller.utils.OnlineEditorUtils.java

public static Map<Object, Object> extractFileInfoMap(File currentFile, String rootPath)
        throws UnsupportedEncodingException {
    Map<Object, Object> info = Maps.newHashMap();
    String name = currentFile.getName();
    info.put("name", name);
    info.put("path",
            URLEncoder.encode(currentFile.getAbsolutePath().replace(rootPath, ""), Constants.ENCODING));
    info.put("canEdit", canEdit(name));
    info.put("hasParent", !currentFile.getPath().equals(rootPath));
    info.put("isParent", hasSubFiles(currentFile));
    info.put("isDirectory", currentFile.isDirectory());
    info.put("root", info.get("path").equals(""));
    info.put("open", info.get("path").equals(""));
    info.put("iconSkin", currentFile.isDirectory() ? CSS_DIRECTORY : CSS_FILE);
    info.put("size", currentFile.length());
    Date modifiedDate = new Date(currentFile.lastModified());
    info.put("lastModified", DateFormatUtils.format(modifiedDate, DATE_PATTERN));
    info.put("lastModifiedForLong", currentFile.lastModified());
    return info;//from   w w w  .jav a 2 s. co m
}

From source file:com.lushapp.utils.SigarUtil.java

/**
 * ??/*w ww  . j av  a 2s.  c  o  m*/
 * @throws Exception
 */
public static ServerStatus getServerStatus() throws Exception {
    ServerStatus status = new ServerStatus();
    status.setServerTime(DateFormatUtils.format(Calendar.getInstance(), "yyyy-MM-dd HH:mm:ss"));
    status.setServerName(System.getenv().get("COMPUTERNAME"));

    Runtime rt = Runtime.getRuntime();
    //status.setIp(InetAddress.getLocalHost().getHostAddress());
    status.setJvmTotalMem(rt.totalMemory() / (1024 * 1024));
    status.setJvmFreeMem(rt.freeMemory() / (1024 * 1024));
    status.setJvmMaxMem(rt.maxMemory() / (1024 * 1024));
    Properties props = System.getProperties();
    status.setServerOs(props.getProperty("os.name") + " " + props.getProperty("os.arch") + " "
            + props.getProperty("os.version"));
    status.setJavaHome(props.getProperty("java.home"));
    status.setJavaVersion(props.getProperty("java.version"));
    status.setJavaTmpPath(props.getProperty("java.io.tmpdir"));

    Sigar sigar = new Sigar();
    getServerCpuInfo(sigar, status);
    getServerDiskInfo(sigar, status);
    getServerMemoryInfo(sigar, status);

    return status;
}

From source file:cn.mypandora.util.MyDateUtils.java

/**
 * ??//  w w  w  . jav  a 2 s  .  com
 *
 * @return
 */
public static String getMonthLastDay() {
    Calendar cal = Calendar.getInstance();
    Calendar f = (Calendar) cal.clone();
    f.clear();
    // 
    // f.set(Calendar.YEAR, cal.get(Calendar.YEAR));
    // f.set(Calendar.MONTH, cal.get(Calendar.MONTH) + 1);
    // f.set(Calendar.MILLISECOND, -1);
    // return DateFormatUtils.format(f, DATE_FORMAT);

    // 
    // f.set(Calendar.YEAR, cal.get(Calendar.YEAR));
    // f.set(Calendar.MONTH, cal.get(Calendar.MONTH));
    // f.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DATE));
    // return DateFormatUtils.format(f, DATE_FORMAT);

    // (?)
    cal.set(Calendar.DATE, 1);// ?1?
    cal.add(Calendar.MONTH, 1);// ?1?
    cal.add(Calendar.DATE, -1);// ???
    return DateFormatUtils.format(cal, DATE_FORMAT);
}

From source file:com.trenako.web.infrastructure.RangeRequestQueryParamsBuilder.java

/**
 * Builds the query parameters for the provided parameters {@code Map}.
 *
 * @param params the parameters/*from  w w  w . java  2 s  . c  om*/
 * @param range  range id
 * @return the query parameters
 * @throws UnsupportedEncodingException
 */
static String buildQueryParams(Map<String, Object> params, String range) throws UnsupportedEncodingException {
    StringBuilder sb = new StringBuilder();

    boolean first = true;
    for (Map.Entry<String, Object> entry : params.entrySet()) {

        if (RANGE_NAMES.contains(entry.getKey()) && !entry.getKey().equals(range)) {
            continue;
        }

        if (first) {
            sb.append("?");
            first = false;
        } else {
            sb.append("&");
        }

        String val;
        if (entry.getValue() instanceof Date) {
            val = DateFormatUtils.format((Date) entry.getValue(),
                    DateFormatUtils.ISO_DATETIME_FORMAT.getPattern());
        } else {
            val = entry.getValue().toString();
        }
        sb.append(entry.getKey()).append("=").append(URLEncoder.encode(val, "UTF-8"));
    }

    return sb.toString();
}

From source file:com.omertron.slackbot.functions.BotWelcome.java

/**
 * Add a user to the list<p>// w  ww  .j  av a2  s  .  c  o m
 * Will also save the file
 *
 * @param username
 */
public static synchronized void addUser(String username) {
    String dateString = DateFormatUtils.format(new Date(), "dd-MM-yyyy HH:mm:ss");
    LOG.info("Adding '{}' to the welcomed list on {}", username, dateString);
    USER_LIST.put(username, dateString);
    // Save the file
    writeFile();
}

From source file:me.j360.idgen.impl.strategy.TimestampStrategy.java

public String makeId(String originalId, Class<?> clazz) {
    return super.getId(originalId, DateFormatUtils.format(new Date(), pattern));
}

From source file:com.ah.be.common.PresenceUtil.java

private static void saveCustoemrInformation(String customerId, HmDomain domain) {
    try {/*from   ww  w . j  a va2 s.c om*/
        long current = System.currentTimeMillis();
        PresenceAnalyticsCustomer customer = new PresenceAnalyticsCustomer();
        customer.setCustomerId(customerId);
        customer.setOwner(domain);
        customer.setCreateAt(
                DateFormatUtils.format(current, DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern()));
        QueryUtil.createBo(customer);
        putPresenceCustomerId(customerId, domain.getId());
    } catch (Exception e) {
        log.error("saveCustoemrInformation error, domain: " + domain.getDomainName());
    }
}