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:Main.java

public static String formatDateForCookie(Date date) {
    // for http cookie
    final String PATTERN_RFC1123 = "EEE, dd MMM yyyy HH:mm:ss zzz";

    SimpleDateFormat format = new SimpleDateFormat(PATTERN_RFC1123, Locale.US);
    format.setTimeZone(TimeZone.getTimeZone("GMT"));

    return format.format(date);
}

From source file:Main.java

@SuppressLint("SimpleDateFormat")
public static String getTimeStringWithGMT(Date date) {
    SimpleDateFormat dateformat = new SimpleDateFormat("yyyy.MM.dd. aa hh:mm (ZZZZ)");
    dateformat.setTimeZone(TimeZone.getDefault());
    return dateformat.format(date);

}

From source file:Main.java

public static String calcFrom(String fromDate, String granularity) throws ParseException {
    String pattern = "";
    if (granularity.equals("YYYY-MM-DDThh:mm:ssZ")) {
        pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'";
    } else {//from w  w w . j a v  a 2 s  . co m
        pattern = "yyyy-MM-dd";
    }

    SimpleDateFormat sdf = new SimpleDateFormat(pattern);
    sdf.setTimeZone(TimeZone.getTimeZone("UTC"));

    return sdf.format(sdf.parse(fromDate));

}

From source file:Main.java

/**
 * //from www. j a  v a 2s  .  co m
 */
public static String millisToGMT(long millis) {
    SimpleDateFormat df = new SimpleDateFormat("MM_dd_yyyy_hh_mm", Locale.getDefault());
    df.setTimeZone(TimeZone.getTimeZone("GMT"));
    return df.format(millis) + "_UTC";
}

From source file:com.ibm.dgaasx.utils.JSONUtils.java

public static SimpleDateFormat getSDFISO8601() {
    SimpleDateFormat sdf = new ISO8601DateTimeFormat();
    sdf.setTimeZone(new SimpleTimeZone(SimpleTimeZone.UTC_TIME, "UTC")); //$NON-NLS-1$
    return sdf;/*from www.j a  v  a  2  s .  c om*/
}

From source file:Main.java

public static SimpleDateFormat getDateFormat() {
    final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.US);
    format.setTimeZone(TimeZone.getTimeZone("UTC"));
    return format;
}

From source file:Main.java

public static long getCurrentGmtTime(String format) {
    final SimpleDateFormat dateFormatGmt = new SimpleDateFormat(format, Locale.getDefault());
    dateFormatGmt.setTimeZone(TimeZone.getTimeZone("GMT"));
    return dateFormatGmt.getCalendar().getTimeInMillis();
}

From source file:Main.java

public static Date ConvertFromWebService(String strDate) {
    String[] formats = new String[] { "yyyy-MM-dd'T'HH:mm:ss.SSS", "yyyy-MM-dd'T'HH:mm:ss.SSSXXX",
            "yyyy-MM-dd'T'HH:mm:ss", "yyyy-MM-dd'T'HH:mm", "yyyy-MM-dd" };
    for (String frm : formats) {
        try {//from  w w  w.j a va2 s  . c  om
            SimpleDateFormat format = new SimpleDateFormat(frm, Locale.US);
            format.setTimeZone(TimeZone.getTimeZone("UTC"));
            return format.parse(strDate);
        } catch (Exception ex) {
        }
    }
    return null;
}

From source file:Main.java

public static String getTime(long millisecond) {
    Date date = new Date(millisecond);
    String time = "";
    if (date != null) {
        SimpleDateFormat df = new SimpleDateFormat("yyyy.MM.dd HH:mm");
        df.setTimeZone(TimeZone.getTimeZone("GMT+08:00"));
        time = df.format(date);/*from  w  w w  . j  ava  2  s  .co  m*/
    }
    return time;
}

From source file:Main.java

public static Date convertStrToDate(String dateStr) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
    dateFormat.setTimeZone(TimeZone.getTimeZone("GMT+0000"));
    Date date = null;/*ww  w . j  a v  a  2s  .  co  m*/
    try {
        date = dateFormat.parse(dateStr);
    } catch (Exception e) {
        date = null;
    }
    return date;
}