Example usage for java.text DateFormat setTimeZone

List of usage examples for java.text DateFormat setTimeZone

Introduction

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

Prototype

public void setTimeZone(TimeZone zone) 

Source Link

Document

Sets the time zone for the calendar of this DateFormat object.

Usage

From source file:microsoft.exchange.webservices.data.core.EwsUtilities.java

private static DateFormat createDateFormat(String format) {
    final DateFormat utcFormatter = new SimpleDateFormat(format);
    utcFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));
    return utcFormatter;
}

From source file:org.esupportail.papercut.services.PayBoxService.java

/**
 * @return current UTC Time - ISO 8601 format
 *//*from   w w w .  j  av a 2  s. c  o  m*/
protected String getCurrentTime() {
    TimeZone tz = TimeZone.getTimeZone("UTC");
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
    df.setTimeZone(tz);
    String nowAsISO = df.format(new Date());
    return nowAsISO;
}

From source file:org.midonet.api.auth.keystone.v2_0.KeystoneService.java

private Token getToken(KeystoneAccess access) throws KeystoneInvalidFormatException {

    Token token = new Token();
    token.setKey(access.getAccess().getToken().getId());

    // Make sure the expired is converted to Date
    String expiredSrc = access.getAccess().getToken().getExpires();
    if (expiredSrc != null) {
        DateFormat df = new SimpleDateFormat(KEYSTONE_TOKEN_EXPIRED_FORMAT);
        df.setTimeZone(TimeZone.getTimeZone("GMT"));
        try {//from w ww .j  av a  2s.c o m
            token.setExpires(df.parse(expiredSrc));
        } catch (ParseException e) {
            throw new KeystoneInvalidFormatException("Unrecognizable keystone expired date format.", e);
        }
    }

    return token;
}

From source file:org.xaloon.core.impl.date.DefaultDateService.java

@Override
public DateFormat getLongDateFormat() {
    SystemPluginBean systemPluginBean = registry.getPluginBean(SystemPlugin.class);
    final DateFormat dateFormat = new SimpleDateFormat(systemPluginBean.getLongDateFormat());
    // Set user timezone if present
    TimeZone timeZone = getCurrentUserTimeZone();
    if (timeZone != null) {
        dateFormat.setTimeZone(timeZone);
    }/*  www. j ava  2 s. co  m*/
    return dateFormat;
}

From source file:ddf.catalog.transformer.common.tika.MetacardCreatorTest.java

private String convertDate(final Date date) {
    final DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
    df.setTimeZone(TimeZone.getTimeZone("UTC"));
    return df.format(date);
}

From source file:org.geoserver.wms.ncwms.GetTimeSeriesResponse.java

@SuppressWarnings("rawtypes")
private void writeCsv(GetFeatureInfoRequest request, FeatureCollectionType results, OutputStream output) {
    Charset charSet = wms.getCharSet();
    OutputStreamWriter osw = new OutputStreamWriter(output, charSet);
    PrintWriter writer = new PrintWriter(osw);

    CoordinateReferenceSystem crs = request.getGetMapRequest().getCrs();
    final Coordinate middle = WMS.pixelToWorld(request.getXPixel(), request.getYPixel(),
            new ReferencedEnvelope(request.getGetMapRequest().getBbox(), crs),
            request.getGetMapRequest().getWidth(), request.getGetMapRequest().getHeight());

    if (crs instanceof ProjectedCRS) {
        writer.println("# X: " + middle.y);
        writer.println("# Y: " + middle.x);
    } else {/*ww w.  j  a va 2 s .c o m*/
        writer.println("# Latitude: " + middle.y);
        writer.println("# Longitude: " + middle.x);
    }
    final List collections = results.getFeature();
    if (collections.size() > 0) {
        SimpleFeatureCollection fc = (SimpleFeatureCollection) collections.get(0);
        writer.println("Time (UTC)," + fc.getSchema().getDescription().toString());

        DateFormat isoFormatter = new SimpleDateFormat(ISO8601_2000_UTC_PATTERN);
        isoFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));
        try (SimpleFeatureIterator fi = fc.features()) {
            while (fi.hasNext()) {
                SimpleFeature f = fi.next();
                Date date = (Date) f.getAttribute("date");
                Double value = (Double) f.getAttribute("value");
                writer.println(isoFormatter.format(date) + "," + value);
            }
        }
    }
    writer.flush();
}

From source file:microsoft.exchange.webservices.data.core.EwsUtilities.java

/**
 * Write trace start element.//  ww  w  . j a  va  2  s  . c  o  m
 *
 * @param writer         the writer to write the start element to
 * @param traceTag       the trace tag
 * @param includeVersion if true, include build version attribute
 * @throws XMLStreamException the XML stream exception
 */
private static void writeTraceStartElement(XMLStreamWriter writer, String traceTag, boolean includeVersion)
        throws XMLStreamException {
    writer.writeStartElement("Trace");
    writer.writeAttribute("Tag", traceTag);
    writer.writeAttribute("Tid", Thread.currentThread().getId() + "");
    Date d = new Date();
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss'Z'");
    df.setTimeZone(TimeZone.getTimeZone("UTC"));
    String formattedString = df.format(d);
    writer.writeAttribute("Time", formattedString);

    if (includeVersion) {
        writer.writeAttribute("Version", EwsUtilities.getBuildVersion());
    }
}

From source file:org.xaloon.core.impl.date.DefaultDateService.java

@Override
public DateFormat getShortDateFormat() {
    SystemPluginBean systemPluginBean = registry.getPluginBean(SystemPlugin.class);
    final DateFormat dateFormat = new SimpleDateFormat(systemPluginBean.getShortDateFormat());

    // Set user timezone if present
    TimeZone timeZone = getCurrentUserTimeZone();
    if (timeZone != null) {
        dateFormat.setTimeZone(timeZone);
    }//from w  w w.ja va  2 s .  co m
    return dateFormat;
}

From source file:org.codehaus.mojo.webstart.generator.AbstractGenerator.java

/**
 * Converts a given date to an explicit timestamp string in UTC time zone.
 *
 * @param date a timestamp to convert.//from w  w w . jav a2s .c o m
 * @return a string representing a timestamp.
 */
private String dateToExplicitTimestampUTC(Date date) {
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    df.setTimeZone(TimeZone.getTimeZone("UTC"));
    return "TS: " + df.format(date) + "Z";
}

From source file:com.persistent.cloudninja.controller.InstanceHealthDataController.java

/**
 * Get the start and end time.//  w  w w  .ja  v a2 s .  c o m
 * @param hour the number of hour difference between start and end time.
 * @return List containing start and end date.
 */
private List<String> getStartEndTime(int hour) {
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.sss");
    dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));

    Calendar cal = Calendar.getInstance();
    String end = dateFormat.format(cal.getTime());
    cal.add(Calendar.HOUR, -hour);
    String start = dateFormat.format(cal.getTime());

    List<String> time = new ArrayList<String>();
    time.add(start);
    time.add(end);
    return time;
}