Example usage for org.apache.http.client.utils DateUtils formatDate

List of usage examples for org.apache.http.client.utils DateUtils formatDate

Introduction

In this page you can find the example usage for org.apache.http.client.utils DateUtils formatDate.

Prototype

public static String formatDate(final Date date, final String pattern) 

Source Link

Document

Formats the given date according to the specified pattern.

Usage

From source file:com.hypersocket.netty.HttpResponseServletWrapper.java

@Override
public void addCookie(Cookie cookie) {

    StringBuffer cookieHeader = new StringBuffer();

    cookieHeader.append(cookie.getName());
    cookieHeader.append("=");
    cookieHeader.append(cookie.getValue());
    if (cookie.getPath() != null) {
        cookieHeader.append("; Path=");
        cookieHeader.append(cookie.getPath());
    }//from  w  ww .j a  v  a 2  s .com
    if (cookie.getDomain() != null) {
        cookieHeader.append("; Domain=");
        cookieHeader.append(cookie.getDomain());
    }
    if (cookie.getMaxAge() > 0) {
        cookieHeader.append("; Max-Age=");
        cookieHeader.append(cookie.getMaxAge());
        /**
         * This breaks IE when date of server and browser do not match
         */
        cookieHeader.append("; Expires=");
        if (cookie.getMaxAge() == 0) {
            cookieHeader.append(DateUtils.formatDate(new Date(10000), DateUtils.PATTERN_RFC1036));
        } else {
            cookieHeader.append(
                    DateUtils.formatDate(new Date(System.currentTimeMillis() + cookie.getMaxAge() * 1000L),
                            DateUtils.PATTERN_RFC1036));
        }
    }

    if (cookie.getSecure()) {
        cookieHeader.append("; Secure");
    }

    /**
     * Make sure we are not adding duplicate cookies
     */
    for (Entry<String, String> entry : response.getHeaders()) {
        if (entry.getKey().equals("Set-Cookie") && entry.getValue().equals(cookieHeader.toString())) {
            return;
        }
    }
    addHeader("Set-Cookie", cookieHeader.toString());

}

From source file:com.uletian.ultcrm.business.entity.Tech.java

public void fillOtherFields() {
    if (this.getTechCourse() != null) {
        this.courseId = this.getTechCourse().getId();
        this.courseName = this.getTechCourse().getName();
        this.courseImg = this.getTechCourse().getLogo();
    }/*  ww w .  j  a  va  2s.co  m*/
    if (this.getTechSery() != null) {
        this.seryId = this.getTechSery().getId();
        this.seryName = this.getTechSery().getName();
    }
    if (this.getTechModel() != null) {
        this.modelId = this.getTechModel().getId();
        this.modelName = this.getTechModel().getName();
    }
    if (this.getBuyDate() != null) {
        this.year = DateUtils.formatDate(this.getBuyDate(), "yyyy");
        this.month = DateUtils.formatDate(this.getBuyDate(), "MM");
    }

}

From source file:com.oneops.controller.jms.InductorListener.java

/**
 * Set the time stamps in the wo/ao for search/analytics 
 * /*from www .  ja va 2  s .co  m*/
 * @param wo
 */
private void setWoTimeStamps(CmsWorkOrderSimpleBase wo) {
    String responseDequeTs = DateUtils.formatDate(new Date(), CmsConstants.SEARCH_TS_PATTERN);
    wo.getSearchTags().put(CmsConstants.RESPONSE_DEQUE_TS, responseDequeTs);

    String closeTime, totalTime;
    try {

        closeTime = String.valueOf(
                (DateUtils.parseDate(responseDequeTs, new String[] { CmsConstants.SEARCH_TS_PATTERN }).getTime()
                        - DateUtils.parseDate(wo.getSearchTags().get(CmsConstants.RESPONSE_ENQUE_TS),
                                new String[] { CmsConstants.SEARCH_TS_PATTERN }).getTime())
                        / 1000.0);
        wo.getSearchTags().put(CmsConstants.CLOSE_TIME, closeTime);
        totalTime = String.valueOf(
                (DateUtils.parseDate(responseDequeTs, new String[] { CmsConstants.SEARCH_TS_PATTERN }).getTime()
                        - DateUtils.parseDate(wo.getSearchTags().get(CmsConstants.REQUEST_ENQUE_TS),
                                new String[] { CmsConstants.SEARCH_TS_PATTERN }).getTime())
                        / 1000.0);
        wo.getSearchTags().put(CmsConstants.TOTAL_TIME, totalTime);
    } catch (Exception e) {
        logger.error("Exception occured while parsing date " + e);
    }
}