Example usage for java.text DateFormat setCalendar

List of usage examples for java.text DateFormat setCalendar

Introduction

In this page you can find the example usage for java.text DateFormat setCalendar.

Prototype

public void setCalendar(Calendar newCalendar) 

Source Link

Document

Set the calendar to be used by this date format.

Usage

From source file:com.cloudera.api.ApiObjectMapper.java

public static DateFormat makeDateFormat(String format) {
    DateFormat dateFormat = new SimpleDateFormat(format);
    Calendar cal = Calendar.getInstance(new SimpleTimeZone(0, "GMT"));
    dateFormat.setCalendar(cal);
    return dateFormat;
}

From source file:com.cloudera.api.ApiObjectMapper.java

public static DateFormat makeISODateFormat() {
    DateFormat iso8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
    Calendar cal = Calendar.getInstance(new SimpleTimeZone(0, "GMT"));
    iso8601.setCalendar(cal);
    return iso8601;
}

From source file:com.collabnet.ccf.core.utils.DateUtil.java

/**
 * Converts the given Date object into another date object with the
 * specified time zone information./*from  ww w.j  a va2s. c o m*/
 * 
 * @param date
 *            - The date that is to be converted to a different time zone.
 * @param toTimeZone
 *            - the time zone to which the date object should be converted.
 * @return the new Date object in the specified time zone.
 * @throws ParseException
 */
public static Date convertDate(Date date, String toTimeZone) throws ParseException {
    Calendar cal = new GregorianCalendar(TimeZone.getTimeZone(toTimeZone));
    cal.setTime(date);
    DateFormat df = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss.SSS Z");
    df.setCalendar(cal);
    return df.parse(df.format(cal.getTime()));
}

From source file:nl.tue.gale.ae.GaleContext.java

public static void addCookie(Resource resource, String name, String value, int age) {
    checkNotNull(name);/*from   w  w w.j a  v a 2 s.co m*/
    if (value == null)
        value = "Null";
    String host = "";
    String path = sc(resource).getContextPath();
    /*
     * if
     * (req(resource).getHeader("User-Agent").contains("compatible; MSIE")
     * && age == 0) { host =
     * URIs.of(req(resource).getRequestURL().toString()) .getHost(); path =
     * "/"; }
     */
    String expires = null;
    if (age >= 0) {
        if (age == 0)
            age = -86400;
        DateFormat df = new SimpleDateFormat("EEE, dd-MMM-yyyy HH:mm:ss z", Locale.US);
        Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT"), Locale.US);
        c.add(Calendar.SECOND, age);
        df.setCalendar(c);
        expires = df.format(c.getTime());
    } else
        expires = "";
    StringBuilder sb = new StringBuilder();
    for (Map.Entry<String, String> entry : ImmutableMap
            .of(name, encodeURL(value), "Expires", expires, "Path", path, "Domain", host).entrySet())
        if (!"".equals(entry.getValue())) {
            sb.append(entry.getKey());
            sb.append("=");
            sb.append(entry.getValue());
            sb.append("; ");
        }
    sb.delete(sb.length() - 2, sb.length());
    resp(resource).setContentType("text/html");
    resp(resource).addHeader("Set-Cookie", sb.toString());
}

From source file:uk.gov.nationalarchives.discovery.taxonomy.batch.scheduler.updateSolrCloudTask.java

private List getNewCategorisedDocuments() {
    if (lastIAViewUpdate != null) {
        return categoriserService.getNewCategorisedDocumentsAfterDocumentAndUpToNSecondsInPast(lastIAViewUpdate,
                nbOfSecondsInPast, bulkUpdateSize);
    } else if (!StringUtils.isEmpty(startDateString)) {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.ENGLISH);
        df.setCalendar(Calendar.getInstance(TimeZone.getTimeZone("UTC")));
        Date startDate;/*from w  w w  .  j a va  2 s .  c  o  m*/
        try {
            startDate = df.parse(startDateString);
            return categoriserService.getNewCategorisedDocumentsFromDateToNSecondsInPast(startDate,
                    nbOfSecondsInPast, bulkUpdateSize);
        } catch (ParseException e) {
            throw new TaxonomyException(TaxonomyErrorType.INVALID_PARAMETER,
                    "the start date provided has wrong format");
        }
    } else {
        return categoriserService.getNewCategorisedDocumentsFromDateToNSecondsInPast(null, nbOfSecondsInPast,
                bulkUpdateSize);
    }
}

From source file:it.jugpadova.blo.JuggerBo.java

/**
 * Update the frienly URLs div.// www. j  a  va  2s  .  co  m
 *
 * @param jugName
 */
@RemoteMethod
public void updateFriendlyUrls(String jugName, String friendlyName) throws UnsupportedEncodingException {
    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    df.setCalendar(cal);
    WebContext wctx = WebContextFactory.get();
    ScriptSession session = wctx.getScriptSession();
    Util util = new Util(session);
    String friendly = jugName;
    if (StringUtils.isNotBlank(friendlyName)) {
        friendly = friendlyName;
    }
    friendly = URLEncoder.encode(friendly, "UTF-8");
    StringBuilder sb = new StringBuilder();
    sb.append("<a href=\"").append(conf.getJugeventsBaseUrl()).append("/ical/").append(friendly).append("\">")
            .append(conf.getJugeventsBaseUrl()).append("/ical/").append(friendly).append("</a><br/>");
    cal.setTime(new Date());
    cal.set(Calendar.DAY_OF_MONTH, 1);
    cal.set(Calendar.MONTH, 0);
    Date startDate = cal.getTime();
    sb.append("<a href=\"").append(conf.getJugeventsBaseUrl()).append("/ical/").append(friendly).append("/")
            .append(df.format(startDate)).append("\">").append(conf.getJugeventsBaseUrl()).append("/ical/")
            .append(friendly).append("/").append(df.format(startDate)).append("</a><br/>");
    cal.set(Calendar.DAY_OF_MONTH, 31);
    cal.set(Calendar.MONTH, 11);
    Date endDate = cal.getTime();
    sb.append("<a href=\"").append(conf.getJugeventsBaseUrl()).append("/ical/").append(friendly).append("/")
            .append(df.format(startDate)).append("/").append(df.format(endDate)).append("\">")
            .append(conf.getJugeventsBaseUrl()).append("/ical/").append(friendly).append("/")
            .append(df.format(startDate)).append("/").append(df.format(endDate)).append("</a><br/>");
    sb.append("<a href=\"").append(conf.getJugeventsBaseUrl()).append("/json/").append(friendly).append("\">")
            .append(conf.getJugeventsBaseUrl()).append("/json/").append(friendly).append("</a><br/>");
    util.setValue("friendlyUrls", sb.toString());
}

From source file:edu.ku.brc.specify.tasks.services.CollectingEventLocalityKMLGenerator.java

/**
 * Generates a KML chunk describing the given collecting event.
 * @param kmlDocument /*w  ww. j av  a 2 s  .  c om*/
 *
 * @param ce the event
 * @param label the label for the event
 * @return the KML string
 */
protected void generatePlacemark(Element kmlDocument, final CollectingEvent ce, final String label) {
    if (ce == null || ce.getLocality() == null || ce.getLocality().getLatitude1() == null
            || ce.getLocality().getLongitude1() == null) {
        return;
    }

    // get all of the important information
    Locality loc = ce.getLocality();
    BigDecimal lat = loc.getLatitude1();
    BigDecimal lon = loc.getLongitude1();

    // get event times
    Calendar start = ce.getStartDate();
    DateFormat dfStart = DateFormat.getDateInstance();

    String startString = "";
    if (start != null) {
        dfStart.setCalendar(start);
        startString = dfStart.format(start.getTime());
    }

    Calendar end = ce.getEndDate();
    DateFormat dfEnd = DateFormat.getDateInstance();

    String endString = "";
    if (end != null) {
        dfEnd.setCalendar(end);
        endString = dfEnd.format(end.getTime());
    }

    // build the placemark
    Element placemark = kmlDocument.addElement("Placemark");
    placemark.addElement("styleUrl").addText("#custom");

    StringBuilder name = new StringBuilder();
    if (label != null) {
        name.append(label);
    }

    if (StringUtils.isNotEmpty(startString)) {
        name.append(startString);
        if (StringUtils.isNotEmpty(endString) && !startString.equals(endString)) {
            name.append(" - ");
            name.append(endString);
        }
    }

    placemark.addElement("name").addText(name.toString());
    // build the fancy HTML popup description

    placemark.addElement("description").addCDATA(generateHtmlDesc(ce));

    GenericKMLGenerator.buildPointAndLookAt(placemark,
            new Pair<Double, Double>(lat.doubleValue(), lon.doubleValue()));
}

From source file:com.thelastcheck.io.base.Field.java

private DateFormat formatForZone(Map<String, DateFormat> map, String format, TimeZone zone) {
    DateFormat df = null;
    if (zone == null) {
        df = map.get(null);/*from   w  w w. j a v a2s  .  co  m*/
    } else {
        df = map.get(zone.getID());
    }
    if (df == null) {
        df = new SimpleDateFormat(format);
        if (zone == null) {
            map.put(null, df);
        } else {
            Calendar cal = Calendar.getInstance(zone);
            df.setCalendar(cal);
            map.put(zone.getID(), df);
        }
    }
    return df;
}

From source file:org.exoplatform.calendar.webui.popup.UIEventForm.java

protected void setEventFromDate(Date date, String dateFormat, String timeFormat) {
    UIEventDetailTab eventDetailTab = getChildById(TAB_EVENTDETAIL);
    UIEventAttenderTab eventAttenderTab = getChildById(TAB_EVENTATTENDER);
    UIFormDateTimePicker fromField = eventDetailTab.getChildById(UIEventDetailTab.FIELD_FROM);
    UIFormComboBox timeField = eventDetailTab.getChildById(UIEventDetailTab.FIELD_FROM_TIME);
    WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
    Locale locale = context.getParentAppRequestContext().getLocale();
    DateFormat df = new SimpleDateFormat(dateFormat, locale);
    df.setCalendar(CalendarUtils.getInstanceOfCurrentCalendar());
    fromField.setValue(df.format(date));
    df = new SimpleDateFormat(timeFormat, locale);
    df.setCalendar(CalendarUtils.getInstanceOfCurrentCalendar());
    timeField.setValue(df.format(date));
    eventAttenderTab.setEventFromDate(date, timeFormat);
}

From source file:org.exoplatform.calendar.webui.popup.UIEventForm.java

protected void setEventToDate(Date date, String dateFormat, String timeFormat) {
    UIEventDetailTab eventDetailTab = getChildById(TAB_EVENTDETAIL);
    UIEventAttenderTab eventAttenderTab = getChildById(TAB_EVENTATTENDER);
    UIFormDateTimePicker toField = eventDetailTab.getChildById(UIEventDetailTab.FIELD_TO);
    UIFormComboBox timeField = eventDetailTab.getChildById(UIEventDetailTab.FIELD_TO_TIME);
    WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
    Locale locale = context.getParentAppRequestContext().getLocale();
    DateFormat df = new SimpleDateFormat(dateFormat, locale);
    df.setCalendar(CalendarUtils.getInstanceOfCurrentCalendar());
    toField.setValue(df.format(date));//from  w ww  .j  a  v  a  2  s  .  c o m
    df = new SimpleDateFormat(timeFormat, locale);
    df.setCalendar(CalendarUtils.getInstanceOfCurrentCalendar());
    timeField.setValue(df.format(date));
    eventAttenderTab.setEventToDate(date, timeFormat);
}