Example usage for java.text SimpleDateFormat setTimeZone

List of usage examples for java.text SimpleDateFormat setTimeZone

Introduction

In this page you can find the example usage for java.text SimpleDateFormat 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.shazam.dataengineering.pipelinebuilder.PipelineObject.java

public static Date getDate(String date) throws java.text.ParseException {
    SimpleDateFormat dateFormat = new SimpleDateFormat(PIPELINE_DATE_FORMAT);
    dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
    return dateFormat.parse(date);
}

From source file:com.tdclighthouse.prototype.utils.TdcUtils.java

public static String dateToRFC1123(Date date) {
    SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT, new Locale("en"));
    dateFormat.setTimeZone(TimeZone.getTimeZone(GMT));
    String result = dateFormat.format(date);
    return result;
}

From source file:DateUtil.java

/**
 * Formats the given date according to the specified pattern.  The pattern
 * must conform to that used by the {@link SimpleDateFormat simple date
 * format} class./*from w  w w  .ja va2 s .  c o  m*/
 *
 * @param date    The date to format.
 * @param pattern The pattern to use for formatting the date.
 * @return A formatted date string.
 * @throws IllegalArgumentException If the given date pattern is invalid.
 * @see SimpleDateFormat
 */
public static String formatDate(Date date, String pattern) {
    if (date == null) {
        throw new IllegalArgumentException("date is null");
    }
    if (pattern == null) {
        throw new IllegalArgumentException("pattern is null");
    }

    SimpleDateFormat formatter = new SimpleDateFormat(pattern, Locale.US);
    formatter.setTimeZone(GMT);
    return formatter.format(date);
}

From source file:airlift.util.FormatUtil.java

public static String format(java.util.Date _date, String _pattern, java.util.TimeZone _timeZone) {
    String date = "";

    try {// w ww . j a v  a 2s.  c o m
        java.text.SimpleDateFormat format = new java.text.SimpleDateFormat(_pattern);
        format.setTimeZone(_timeZone);

        if (_date != null) {
            date = format.format(_date);
        }
    } catch (Throwable t) {
        throw new RuntimeException(t);
    }

    return date;
}

From source file:com.clustercontrol.util.HinemosTime.java

/**
 * Hinemos??HinemosManager?????<br>
 * @return//from ww w . j a  v  a  2  s .c  om
 */
public static String getDateString() {
    SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss XXX yyyy", Locale.US);
    sdf.setTimeZone(HinemosTime.getTimeZone());
    return sdf.format(currentTimeMillis());
}

From source file:fm.audiobox.core.utils.ModelUtil.java

/**
 * Given a string representing an UTC date provided by AudioBox server,
 * this method returns a unix timestamp (always in UTC).
 *
 * @param simpleDateFormat the simple date format
 * @param audioboxDate     the string date provided by audiobox server.
 *
 * @return unix timestamp// w ww  . j  a  va 2  s .c  om
 *
 * @throws ParseException the parse exception
 */
public static long toUnixTime(SimpleDateFormat simpleDateFormat, String audioboxDate) throws ParseException {

    simpleDateFormat.applyPattern(AUDIOBOX_DATE_FORMAT);
    simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
    Date date = simpleDateFormat.parse(audioboxDate);
    return date.getTime();
}

From source file:com.zimbra.examples.extns.samlprovider.SamlAuthProvider.java

private static Element getSamlAssertionRequest(String samlAssertionId) {
    Element envelope = new Element.XMLElement(new QName("Envelope", SoapProtocol.Soap11.getNamespace()));
    Element body = envelope.addElement(new QName("Body", SoapProtocol.Soap11.getNamespace()));
    Element requestElt = body.addElement(new QName("AssertionIDRequest", SAML_PROTOCOL_NS));
    Date now = new Date();
    requestElt.addAttribute("ID", "id-" + now.getTime());
    requestElt.addAttribute("Version", "2.0");
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
    dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
    requestElt.addAttribute("IssueInstant", dateFormat.format(now));
    Element idRefElt = requestElt.addElement(new QName("AssertionIDRef", SAML_PROTOCOL_NS));
    idRefElt.addText(samlAssertionId);/*from  ww  w  .ja v  a 2  s. co m*/
    return envelope;
}

From source file:ISO8601DateParser.java

public static String toString(Date date) {

    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz");

    TimeZone tz = TimeZone.getTimeZone("UTC");

    df.setTimeZone(tz);

    String output = df.format(date);

    int inset0 = 9;
    int inset1 = 6;

    String s0 = output.substring(0, output.length() - inset0);
    String s1 = output.substring(output.length() - inset1, output.length());

    String result = s0 + s1;//from   w  ww . ja  v a2  s .  com

    result = result.replaceAll("UTC", "+00:00");

    return result;

}

From source file:com.amazonaws.sqs.util.SQSClient.java

private static String getExpires() {
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.MINUTE, 60);

    SimpleTimeZone timeZone = new SimpleTimeZone(0, "PST");

    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz");
    format.setTimeZone(timeZone);
    String timestampStr = format.format(cal.getTime());

    return timestampStr;
}

From source file:com.vmware.identity.rest.core.util.RequestSigner.java

/**
 * Convert a date into the format utilized by web browsers
 * (i.e. "EEE, dd MMM yyyy HH:mm:ss z").
 *
 * @param date the date to convert into a timestamp.
 * @return the formatted timestamp string.
 *//*from  w w w.  jav a2s .  co  m*/
public static String getHttpFormattedDate(Date date) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
    dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
    return dateFormat.format(date);
}