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

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

Introduction

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

Prototype

public static String format(Date date, String pattern) 

Source Link

Document

Formats a date/time into a specific pattern.

Usage

From source file:net.shopxx.service.impl.SmsServiceImpl.java

private void send(String[] mobiles, String content, Date sendTime) {
    Assert.notEmpty(mobiles);/*from  ww w .  j  ava2s  .c o  m*/
    Assert.hasText(content);

    Setting setting = SystemUtils.getSetting();
    String smsSn = setting.getSmsSn();
    String smsKey = setting.getSmsKey();
    if (StringUtils.isEmpty(smsSn) || StringUtils.isEmpty(smsKey)) {
        return;
    }
    try {
        Client client = new Client(smsSn, smsKey);
        if (sendTime != null) {
            client.sendScheduledSMS(mobiles, content, DateFormatUtils.format(sendTime, "yyyyMMddhhmmss"));
        } else {
            client.sendSMS(mobiles, content, 5);
        }
    } catch (Exception e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:hello.preferences.PreferenceBasedGreetingServiceImpl.java

private void add(final Greeting greeting, final String pathName) {
    //  create new node with greeting
    final Preferences greetingsNode = getGreetingsNode().node(pathName);
    final Preferences node = greetingsNode
            .node(DateFormatUtils.format(greeting.getCreated(), "yyyyMMddHHmmssSSS"));

    // populate/*from w w  w .j a v  a 2s .  c  om*/
    node.putLong(KEY_CREATED, greeting.getCreated());
    node.put(KEY_TEXT, greeting.getText());
    node.put(KEY_SUBMITTED_BY, greeting.getSubmittedBy());
    if ((greeting.getProcessedBy() != null) && (greeting.getProcessedOn() > 0)) {
        node.putLong(KEY_PROCESSED_ON, greeting.getProcessedOn());
        node.put(KEY_PROCESSED_BY, greeting.getProcessedBy());
    }

    // flush
    try {
        greetingsNode.flush();
    } catch (final BackingStoreException e) {
        throw new RuntimeException("Error persisting greeting!", e);
    }
}

From source file:com.athena.peacock.agent.scheduler.quartz.BaseJob.java

/**
* <pre>//from ww w . jav  a  2 s.c o m
* Trigger? ? ? Quartz Job?  
* </pre>
* @param context
* @throws JobExecutionException
* @see org.quartz.Job#execute(org.quartz.JobExecutionContext)
*/
public void execute(JobExecutionContext context) throws JobExecutionException {
    logger.debug("? (JOB)? ??.[job: {} , instance: {}, start: {}]",
            new Object[] { context.getJobDetail().getFullName(), context.getJobInstance().toString(),
                    DateFormatUtils.format(System.currentTimeMillis(), LOGGING_DATE_FORMAT) });

    initializingContext(context);

    // TODO   
    JobExecution wrapper = JobExecution.newExecution(context);

    try {
        //  
        beforeJob(wrapper);

        //  
        executeInternal(wrapper);

        //  
        afterJob(wrapper);

        wrapper.getJobStatus().complete();
    } catch (Exception e) {
        if (logger.isErrorEnabled()) {
            logger.error("(JOB)?    ?  .[job: "
                    + context.getJobDetail().getFullName() + ", instance:" + context.getJobInstance().toString()
                    + " , interrupt: " + DateFormatUtils.format(System.currentTimeMillis(), LOGGING_DATE_FORMAT)
                    + "]", e);
        }

        wrapper.getJobStatus().fail();
        onError(wrapper, e);
        throw new JobExecutionException("Job     ?", e);
    }

    logger.debug("(JOB)? ? ? .[job: {} , instance: {}, end: {}]",
            new Object[] { context.getJobDetail().getFullName(), context.getJobInstance().toString(),
                    DateFormatUtils.format(System.currentTimeMillis(), LOGGING_DATE_FORMAT) });
}

From source file:com.dianping.wed.cache.redis.WeddingRedisMonitorServiceImplTest.java

@Test
public void testFindSlowQuery() {
    String nodeListString = ConfigCache.getInstance().getProperty(JedisFactory.REDIS_NODE_LIST_KEY);
    String[] nodeListArr = nodeListString.split(";");
    int nodeListSize = nodeListArr.length;
    for (int i = 0; i < nodeListSize; ++i) {
        String[] machines = nodeListArr[i].split(",");
        for (String machine : machines) {
            List<WeddingRedisSlowLogDTO> slowLogList = weddingRedisMonitorService.findSlowQuery(machine, 100);
            for (WeddingRedisSlowLogDTO slowLogDTO : slowLogList) {
                System.out.println(DateFormatUtils.format(slowLogDTO.getDate(), "yyyy-MM-dd HH:mm:ss") + " "
                        + slowLogDTO.getExecutionTime() / 1000 + "ms " + slowLogDTO.getQuery());
            }//from  w w  w  .j a v a  2s.  c  om
        }
    }
}

From source file:gemlite.core.common.DateUtil.java

public static String format(Date dt, String fmtStr) {
    if (dt == null)
        return "";
    String str = DateFormatUtils.format(dt, fmtStr);
    return str;/*from  w  ww.  ja v  a  2 s.c  o  m*/
}

From source file:cn.vlabs.umt.services.requests.impl.RequestMails.java

public void sendDenyUser(UserRequest request, UMTContext context) {
    Properties prop = new Properties();
    setProperty(prop, "username", request.getUsername());
    setProperty(prop, "truename", request.getTruename());
    setProperty(prop, "orgnization", request.getOrgnization());
    setProperty(prop, "phonenumber", request.getPhonenumber());
    setProperty(prop, "createtime", DateFormatUtils.format(request.getCreateTime(), "yyyy-MM-dd"));
    setProperty(prop, "CurrentDate", DateFormatUtils.format(new Date(), "yyyy-MM-dd"));

    setProperty(prop, "UserTrueName", request.getTruename());

    try {//from ww  w .j a v  a  2  s . c om
        sender.send(context.getLocale(), request.getEmail(), EmailTemplate.TARGET_DENY, prop);
    } catch (MailException e) {
        log.error(e.getMessage());
        log.debug("information", e);
    }
}

From source file:cn.ipanel.apps.portalBackOffice.util.CommonsFiend.java

public static String getCurrentDateTime() {
    return DateFormatUtils.format(Calendar.getInstance().getTime(), Defines.FORMAT_DATE_TIME_STRING);
}

From source file:ch.systemsx.cisd.openbis.generic.server.business.bo.PropertyValidatorTest.java

@SuppressWarnings("unused")
@DataProvider//from   w w w  . j a  v  a  2s  .  c  om
private final static Object[][] getNonWorkingValues() {
    return new Object[][] { { createTimestampPropertyType(), DateFormatUtils.format(new Date(), "yyyy") },
            { createIntegerPropertyType(), "a" }, { createIntegerPropertyType(), "1.1" },
            { createRealPropertyType(), "b" }, { createBooleanPropertyType(), "BOB" }, };
}

From source file:info.magnolia.cms.gui.dialog.DialogDate.java

/**
 * Customize the dialog.//from  ww w .  j av  a  2  s .  c  o m
 * @see info.magnolia.cms.gui.dialog.DialogEditWithButton#doBeforeDrawHtml()
 */
protected void doBeforeDrawHtml() {
    super.doBeforeDrawHtml();

    // set buttonlabel in config
    this.getButton().setLabel(MessagesManager.get("dialog.date.select")); //$NON-NLS-1$
    this.getButton().setSaveInfo(false);
    this.getButton().setOnclick(
            "mgnlDialogOpenCalendar('" + this.getName() + "'," + this.getConfigValue("time", "false") + ");"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
    String format = "yyyy-MM-dd"; //$NON-NLS-1$
    String pattern = "XXXX-XX-XX"; //$NON-NLS-1$
    if (!this.getConfigValue("time", "false").equals("false")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        format += "'T'HH:mm:ss"; //$NON-NLS-1$
        pattern += "TXX:XX:XX"; //$NON-NLS-1$
    }
    this.setConfig("onchange", "mgnlDialogDatePatternCheck(this,'" + pattern + "');"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

    if (this.getWebsiteNode() != null && this.getWebsiteNode().getNodeData(this.getName()).isExist()) {
        Calendar valueCalendar = this.getWebsiteNode().getNodeData(this.getName()).getDate();

        // valueCalendar is in UTC  turn it back into the current timezone
        if (valueCalendar != null) {
            Calendar local = DateUtil.getLocalCalendarFromUTC(valueCalendar);
            this.setValue(DateFormatUtils.format(local.getTime(), format));

        }
    }
    // check this!
    this.setConfig("type", this.getConfigValue("type", PropertyType.TYPENAME_DATE)); //$NON-NLS-1$ //$NON-NLS-2$
}

From source file:gemlite.core.common.DateUtil.java

public static String format(Date dt) {
    if (dt == null)
        return "";
    String str = DateFormatUtils.format(dt, "yyyyMMdd");
    return str;//from w w w.  java 2  s .c  o m
}