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:com.casker.portfolio.service.PortfolioServiceImpl.java

private long makeNo() {
    return Long.parseLong(DateFormatUtils.format(new Date(), "yyMMddhhmmss"));
}

From source file:com.sangupta.shire.generators.SiteMapGenerator.java

/**
 * @see com.sangupta.shire.core.Generator#execute(com.sangupta.shire.model.TemplateData)
 *///from  w ww . j a va  2  s.c  o  m
@Override
public void execute(Shire shire) {
    StringBuilder builder = new StringBuilder();

    builder.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
    builder.append("<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n");
    String url = shire.getTemplateData().getSite().getUrl();

    List<RenderableResource> resources = shire.getSiteDirectory().getRenderableResources();
    if (resources != null && resources.size() > 0) {
        for (RenderableResource resource : resources) {
            builder.append("  <url>\n");

            builder.append("    <loc>");
            builder.append(url);

            String resourceURL = shire.getSiteWriter().getURL(resource);
            if (!resourceURL.startsWith("/")) {
                builder.append("/");
            }
            builder.append(resourceURL);
            builder.append("</loc>\n");

            builder.append("    <lastmod>");
            builder.append(DateFormatUtils.format(resource.getPublishDate(), "yyyy-MM-dd"));
            builder.append("</lastmod>\n");

            builder.append("    <changefreq>");
            builder.append(SiteMapChangeFrequency.monthly);
            builder.append("</changefreq>\n");

            builder.append("    <priority>");
            builder.append("0.5");
            builder.append("</priority>\n");

            builder.append("  </url>\n");
        }
    }

    builder.append("</urlset>\n");

    // create a resource of this file
    GeneratedResource resource = new GeneratedResource("/sitemap.xml", builder.toString());

    // export it
    shire.getSiteWriter().export(resource);
}

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

/**
 * //from ww  w . j  ava2s .co m
 *
 * @return
 */
public static String getPreviousMonthFirst() {
    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.DATE, 1);
    // return DateFormatUtils.format(f, DATE_FORMAT);

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

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

From source file:com.daphne.es.monitor.web.controller.EhcacheMonitorController.java

@RequestMapping("{cacheName}/{key}/details")
@ResponseBody/*from   w  w  w .  j  a  v a  2  s . c  om*/
public Object keyDetail(@PathVariable("cacheName") String cacheName, @PathVariable("key") String key,
        Model model) {

    Element element = cacheManager.getCache(cacheName).get(key);

    String dataPattern = "yyyy-MM-dd hh:mm:ss";
    Map<String, Object> data = Maps.newHashMap();
    data.put("objectValue", element.getObjectValue().toString());
    data.put("size", PrettyMemoryUtils.prettyByteSize(element.getSerializedSize()));
    data.put("hitCount", element.getHitCount());

    Date latestOfCreationAndUpdateTime = new Date(element.getLatestOfCreationAndUpdateTime());
    data.put("latestOfCreationAndUpdateTime",
            DateFormatUtils.format(latestOfCreationAndUpdateTime, dataPattern));
    Date lastAccessTime = new Date(element.getLastAccessTime());
    data.put("lastAccessTime", DateFormatUtils.format(lastAccessTime, dataPattern));
    if (element.getExpirationTime() == Long.MAX_VALUE) {
        data.put("expirationTime", "?");
    } else {
        Date expirationTime = new Date(element.getExpirationTime());
        data.put("expirationTime", DateFormatUtils.format(expirationTime, dataPattern));
    }

    data.put("timeToIdle", element.getTimeToIdle());
    data.put("timeToLive", element.getTimeToLive());
    data.put("version", element.getVersion());

    return data;

}

From source file:com.lehealth.common.sdk.CCPRestSDK.java

/**
 * ???/*  w  ww . j a va 2  s  .co m*/
 * 
 * @param to
 *            ? ??????????100
 * @param templateId
 *            ? ?Id
 * @param datas
 *            ?? ???{??}
 * @return
 */
public JSONObject sendTemplateSMS(String to, String templateId, String[] datas, String domain, String appId,
        String sid, String token) {
    JSONObject errorInfo = this.accountValidate(domain, appId, sid, token);
    if (errorInfo != null) {
        return errorInfo;
    }

    if (StringUtils.isBlank(to) || StringUtils.isBlank(appId) || StringUtils.isBlank(templateId)) {
        throw new IllegalArgumentException("?:" + (StringUtils.isBlank(to) ? " ?? " : "")
                + (StringUtils.isBlank(templateId) ? " ?Id " : "") + "");
    }

    String timestamp = DateFormatUtils.format(new Date(), Constant.dateFormat_yyyymmddhhmmss);
    String acountName = sid;
    String sig = sid + token + timestamp;
    String acountType = "Accounts";
    String signature = DigestUtils.md5Hex(sig);
    String url = getBaseUrl(domain).append("/" + acountType + "/").append(acountName)
            .append("/" + TemplateSMS + "?sig=").append(signature).toString();

    String src = acountName + ":" + timestamp;
    String auth = Base64.encodeBase64String(src.getBytes());
    Map<String, String> header = new HashMap<String, String>();
    header.put("Accept", "application/json");
    header.put("Content-Type", "application/json;charset=utf-8");
    header.put("Authorization", auth);

    JSONObject json = new JSONObject();
    json.accumulate("appId", appId);
    json.accumulate("to", to);
    json.accumulate("templateId", templateId);
    if (datas != null) {
        JSONArray Jarray = new JSONArray();
        for (String s : datas) {
            Jarray.add(s);
        }
        json.accumulate("datas", Jarray);
    }
    String requestBody = json.toString();

    DefaultHttpClient httpclient = null;
    HttpPost postMethod = null;
    try {
        httpclient = new CcopHttpClient().registerSSL(domain, NumberUtils.toInt(SERVER_PORT), "TLS", "https");
        postMethod = new HttpPost(url);
        if (header != null && !header.isEmpty()) {
            for (Entry<String, String> e : header.entrySet()) {
                postMethod.setHeader(e.getKey(), e.getValue());
            }
        }
        postMethod.setConfig(PoolConnectionManager.requestConfig);
        BasicHttpEntity requestEntity = new BasicHttpEntity();
        requestEntity.setContent(new ByteArrayInputStream(requestBody.getBytes("UTF-8")));
        requestEntity.setContentLength(requestBody.getBytes("UTF-8").length);
        postMethod.setEntity(requestEntity);

        HttpResponse response = httpclient.execute(postMethod);

        HttpEntity entity = response.getEntity();
        if (entity != null) {
            String result = EntityUtils.toString(entity, "UTF-8");
            EntityUtils.consume(entity);
            return JSONObject.fromObject(result);
        }
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (postMethod != null) {
            postMethod.releaseConnection();
        }
        if (httpclient != null) {
            httpclient.getConnectionManager().shutdown();
        }
    }
    return getMyError("999999", "");
}

From source file:com.daphne.es.personal.calendar.web.controller.CalendarController.java

@RequestMapping("/load")
@ResponseBody// ww  w. j a  va 2 s  . c  o m
public Collection<Map> ajaxLoad(Searchable searchable, @CurrentUser User loginUser) {
    searchable.addSearchParam("userId_eq", loginUser.getId());
    List<Calendar> calendarList = calendarService.findAllWithNoPageNoSort(searchable);

    return Lists.<Calendar, Map>transform(calendarList, new Function<Calendar, Map>() {
        @Override
        public Map apply(Calendar c) {
            Map<String, Object> m = Maps.newHashMap();

            Date startDate = new Date(c.getStartDate().getTime());
            Date endDate = DateUtils.addDays(startDate, c.getLength() - 1);
            boolean allDays = c.getStartTime() == null && c.getEndTime() == null;

            if (!allDays) {
                startDate.setHours(c.getStartTime().getHours());
                startDate.setMinutes(c.getStartTime().getMinutes());
                startDate.setSeconds(c.getStartTime().getSeconds());
                endDate.setHours(c.getEndTime().getHours());
                endDate.setMinutes(c.getEndTime().getMinutes());
                endDate.setSeconds(c.getEndTime().getSeconds());
            }

            m.put("id", c.getId());
            m.put("start", DateFormatUtils.format(startDate, "yyyy-MM-dd HH:mm:ss"));
            m.put("end", DateFormatUtils.format(endDate, "yyyy-MM-dd HH:mm:ss"));
            m.put("allDay", allDays);
            m.put("title", c.getTitle());
            m.put("details", c.getDetails());
            if (StringUtils.isNotEmpty(c.getBackgroundColor())) {
                m.put("backgroundColor", c.getBackgroundColor());
                m.put("borderColor", c.getBackgroundColor());
            }
            if (StringUtils.isNotEmpty(c.getTextColor())) {
                m.put("textColor", c.getTextColor());
            }
            return m;
        }
    });
}

From source file:eionet.webq.dto.FileInfo.java

/**
 * Get user-friendly formatted file creation date.
 *
 * @return created date in String format
 *//*from  w w w .java  2s. co m*/
@XmlElement(name = "created")
public String getCreated() {
    return (createdDate != null) ? DateFormatUtils.format(createdDate, USERFRIENDLY_DATE_FORMAT) : null;
}

From source file:com.mmone.gpdati.allotment.record.AllotmentRecord.java

public String getDateToYMD() throws ParseException {
    return DateFormatUtils.format(getJDateTo(), "yyyyMMdd");
}

From source file:com.framework.demo.web.controller.calendar.CalendarController.java

@RequestMapping("/load")
@ResponseBody//w  ww.j  a v  a2  s  .c  o m
public Collection<Map> ajaxLoad(Searchable searchable, @CurrentUser SysUser loginUser) {
    searchable.addSearchParam("userId_eq", loginUser.getId());
    List<PersonalCalendar> calendarList = calendarService.findAllWithNoPageNoSort(searchable);

    return Lists.<PersonalCalendar, Map>transform(calendarList, new Function<PersonalCalendar, Map>() {

        public Map apply(PersonalCalendar c) {
            Map<String, Object> m = Maps.newHashMap();

            Date startDate = new Date(c.getStartDate().getTime());
            Date endDate = DateUtils.addDays(startDate, c.getLength() - 1);
            boolean allDays = c.getStartTime() == null && c.getEndTime() == null;

            if (!allDays) {
                startDate.setHours(c.getStartTime().getHours());
                startDate.setMinutes(c.getStartTime().getMinutes());
                startDate.setSeconds(c.getStartTime().getSeconds());
                endDate.setHours(c.getEndTime().getHours());
                endDate.setMinutes(c.getEndTime().getMinutes());
                endDate.setSeconds(c.getEndTime().getSeconds());
            }

            m.put("id", c.getId());
            m.put("start", DateFormatUtils.format(startDate, "yyyy-MM-dd HH:mm:ss"));
            m.put("end", DateFormatUtils.format(endDate, "yyyy-MM-dd HH:mm:ss"));
            m.put("allDay", allDays);
            m.put("title", c.getTitle());
            m.put("details", c.getDetails());
            if (StringUtils.isNotEmpty(c.getBackgroundColor())) {
                m.put("backgroundColor", c.getBackgroundColor());
                m.put("borderColor", c.getBackgroundColor());
            }
            if (StringUtils.isNotEmpty(c.getTextColor())) {
                m.put("textColor", c.getTextColor());
            }
            return m;
        }
    });
}

From source file:jp.dip.komusubi.botter.gae.module.jal5971.EntryParser.java

protected String getDateHeading(String content) {
    Resolver<Date> resolver = CONTEXT.getResolverManager().getDateResolver();
    Calendar cal = Calendar.getInstance();
    cal.setTime(resolver.resolve());//w  w w  .j  a  v  a  2s  .c  o  m
    cal.add(Calendar.DAY_OF_MONTH, 1);

    String dateHeading = null;
    boolean find = false;
    for (int i = 0; i < LEFT_BRACES.length; i++) {
        dateHeading = LEFT_BRACES[i] + KEYWORD_TOMORROW + DateFormatUtils.format(cal, "d") + KEYWORD_DAY
                + RIGHT_BRACES[i];
        if (content.contains(dateHeading)) {
            find = true;
            break;
        }
    }
    if (!find)
        throw new ParseException("left brace?????: " + content);
    return dateHeading;
}