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:com.jaspersoft.jasperserver.war.common.JasperServerUtil.java

public static String formatDate(MessageSource messages, Date date, TimeZone timeZone) {
    DateFormat format = createCalendarDateTimeFormat(messages);
    format.setTimeZone(timeZone);
    return format.format(date);
}

From source file:no.met.jtimeseries.chart.Utility.java

/**
 * Calculate the time at the threshold value
 * /*  w ww.ja va2 s.co  m*/
 * @param time1
 *            The first time string
 * @param value1
 *            The first value
 * @param time2
 *            The second time String
 * @param value2
 *            The second value
 * @param value3
 *            The threshold value
 * @return The time at the threshold
 */
public static Date timeOfThreshold(Date time1, double value1, Date time2, double value2, double value3) {
    DateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
    dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
    long date3 = 0;
    long date1 = time1.getTime();
    long date2 = time2.getTime();

    double slope = (date2 - date1) / (value2 - value1);
    double bias = date2 - slope * value2;
    date3 = new Double(slope * value3 + bias).longValue();
    return new Date(date3);
}

From source file:illab.nabal.util.Util.java

/**
 * Get ISO 8601 date and time format./* w w w .  java  2  s . c  o  m*/
 * 
 * @return DateFormat
 * @throws Exception
 */
public static DateFormat getIso8601DateFormat(TimeZone timeZone, Locale locale) throws Exception {

    // check timezone parameter
    if (timeZone == null)
        throw new SystemException("Invalid timezone parameter.");

    // check locale parameter
    if (locale == null)
        throw new SystemException("Invalid locale parameter.");

    DateFormat iso8601Format = new SimpleDateFormat(SystemProperties.ISO_8601_DATE_FORMAT, locale);
    iso8601Format.setTimeZone(timeZone);

    return iso8601Format;
}

From source file:nl.ellipsis.webdav.server.methods.AbstractMethod.java

public static String creationDateFormat(final Date date) {
    DateFormat df = thCreationDateFormat.get();
    if (df == null) {
        df = new SimpleDateFormat(CREATION_DATE_FORMAT);
        df.setTimeZone(TimeZone.getTimeZone(TIMEZONE_GMT));
        thCreationDateFormat.set(df);//from w  ww .java2 s  .  c o  m
    }
    return df.format(date);
}

From source file:ch.qos.logback.core.pattern.parser2.PatternParser.java

private static DateFormat parseDateFormat(String option) {
    TimeZone tz = null;/*from   ww  w .  ja v  a  2s  . c  o  m*/

    // default to ISO8601 if no conversion pattern given
    if (option == null || option.isEmpty() || option.equalsIgnoreCase(CoreConstants.ISO8601_STR)) {
        option = CoreConstants.ISO8601_PATTERN;
    }

    // Parse the last option in the conversion pattern as a time zone.
    // Make sure the comma is not escaped/quoted.
    int idx = option.lastIndexOf(",");
    if ((idx > -1) && (idx + 1 < option.length() && !ParserUtil.isEscaped(option, idx)
            && !ParserUtil.isQuoted(option, idx))) {

        // make sure the string isn't the millisecond pattern, which
        // can appear after a comma
        String tzStr = option.substring(idx + 1).trim();
        if (!tzStr.startsWith("SSS")) {
            option = option.substring(0, idx);
            tz = TimeZone.getTimeZone(tzStr);
            if (!tz.getID().equalsIgnoreCase(tzStr)) {
                logger().warn("Time zone (\"{}\") defaulting to \"{}\".", tzStr, tz.getID());
            }
        }
    }

    // strip quotes from date format because SimpleDateFormat doesn't understand them
    if (option.length() > 1 && option.startsWith("\"") && option.endsWith("\"")) {
        option = option.substring(1, option.length() - 1);
    }

    DateFormat format = new SimpleDateFormat(option);
    format.setLenient(true);

    if (tz != null) {
        format.setTimeZone(tz);
    }

    return format;
}

From source file:password.pwm.util.java.JavaHelper.java

public static String toIsoDate(final Date date) {
    if (date == null) {
        return "";
    }//from   ww  w .  j  ava  2 s . c o  m

    final DateFormat dateFormat = new SimpleDateFormat(PwmConstants.DEFAULT_DATETIME_FORMAT_STR,
            PwmConstants.DEFAULT_LOCALE);

    dateFormat.setTimeZone(PwmConstants.DEFAULT_TIMEZONE);

    return dateFormat.format(date);
}

From source file:nl.ellipsis.webdav.server.methods.AbstractMethod.java

public static String lastModifiedDateFormat(final Date date) {
    DateFormat df = thLastmodifiedDateFormat.get();
    if (df == null) {
        df = new SimpleDateFormat(LAST_MODIFIED_DATE_FORMAT, Locale.US);
        df.setTimeZone(TimeZone.getTimeZone(TIMEZONE_GMT));
        thLastmodifiedDateFormat.set(df);
    }//from   ww w.  j ava 2 s .c o  m
    return df.format(date);
}

From source file:com.taobao.tdhs.client.util.ConvertUtil.java

public static Long getTimeFromString(String stringVal, @Nullable Calendar cal) throws SQLException {
    if (stringVal == null) {
        return null;
    }//from   ww w  .  ja  v a  2s .c  o  m
    String val = stringVal.trim();
    if (val.length() == 0) {
        return null;
    }
    if (val.equals("0") || val.equals("0000-00-00") || val.equals("0000-00-00 00:00:00")
            || val.equals("00000000000000") || val.equals("0")) {
        Calendar calendar = null;
        if (cal != null) {
            calendar = Calendar.getInstance(cal.getTimeZone());
        } else {
            calendar = Calendar.getInstance();
        }
        calendar.set(Calendar.YEAR, 1);
        calendar.set(Calendar.MONTH, 0);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        return calendar.getTimeInMillis();
    }

    DateFormat dateFormat;
    if (val.length() == "yyyy-MM-dd".length()) {
        dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    } else {
        dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    }
    if (cal != null) {
        TimeZone timeZone = cal.getTimeZone();
        dateFormat.setTimeZone(timeZone);
    }
    try {
        return dateFormat.parse(val).getTime();
    } catch (ParseException e) {
        throw new SQLException("Parse date failure:" + val);
    }
}

From source file:MimeUtil.java

/**
 * Formats the specified date into a RFC 822 date-time string.
 * /*from ww w  . ja v  a 2  s  .com*/
 * @param date
 *            date to be formatted into a string.
 * @param zone
 *            the time zone to use or <code>null</code> to use the default
 *            time zone.
 * @return the formatted time string.
 */
public static String formatDate(Date date, TimeZone zone) {
    DateFormat df = RFC822_DATE_FORMAT.get();

    if (zone == null) {
        df.setTimeZone(TimeZone.getDefault());
    } else {
        df.setTimeZone(zone);
    }

    return df.format(date);
}

From source file:com.wandrell.example.swss.test.util.factory.SecureSoapMessages.java

/**
 * Generates the current date in the format expected by the SOAP message.
 *
 * @return the current date/*from   w w  w . jav  a2  s  .c  o m*/
 */
private static final String getCurrentDate() {
    final DateFormat format; // Format to apply

    // Zulu time format
    format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
    format.setTimeZone(TimeZone.getTimeZone("UTC"));

    return format.format(new Date());
}