Example usage for java.util TimeZone getTimeZone

List of usage examples for java.util TimeZone getTimeZone

Introduction

In this page you can find the example usage for java.util TimeZone getTimeZone.

Prototype

public static TimeZone getTimeZone(ZoneId zoneId) 

Source Link

Document

Gets the TimeZone for the given zoneId .

Usage

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 String getTime(Long timestamp) {
    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm", Locale.getDefault());
    sdf.setTimeZone(TimeZone.getTimeZone("GMT+0"));
    Date date = new Date(timestamp * 1000);
    sdf.format(date);/* www  .  j a v a 2s.c  om*/
    return sdf.format(date);
}

From source file:Main.java

public static String getCurrentUTCTime() {
    SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
    Date t = new Date();
    df1.setTimeZone(TimeZone.getTimeZone("UTC"));
    return df1.format(t);
}

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;//from   ww  w.  ja va 2  s.c om
    try {
        date = dateFormat.parse(dateStr);
    } catch (Exception e) {
        date = null;
    }
    return date;
}

From source file:Main.java

public static long convertTime(long timestamp, String fromTimeZone, String toTimeZone) {
    Calendar fromCal = new GregorianCalendar(TimeZone.getTimeZone(fromTimeZone));
    fromCal.setTimeInMillis(timestamp);/*www.j  ava2s  .  com*/
    Calendar toCal = new GregorianCalendar(TimeZone.getTimeZone(toTimeZone));
    toCal.setTimeInMillis(fromCal.getTimeInMillis());
    return toCal.getTimeInMillis();
}

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 long convertTZ(long timestamp, String fromTimeZone, String toTimeZone) {
    Calendar fromCal = new GregorianCalendar(TimeZone.getTimeZone(fromTimeZone));
    fromCal.setTimeInMillis(timestamp);//ww  w.ja  v a 2s.  c o  m
    Calendar toCal = new GregorianCalendar(TimeZone.getTimeZone(toTimeZone));
    toCal.setTimeInMillis(fromCal.getTimeInMillis());
    return toCal.getTimeInMillis();
}

From source file:Main.java

private static String getFormattedStringFromDate(Date date) {
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    simpleDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
    return simpleDateFormat.format(date);
}

From source file:Main.java

static public int getTimestamp() {
    Calendar calendar = GregorianCalendar.getInstance(TimeZone.getTimeZone("GMT"));
    long millis = calendar.getTimeInMillis();
    long stamp = millis - mCalendarGenMs;

    stamp = (stamp + 500) / 1000;/*from ww  w  . j  av a 2s  .c  om*/
    return (int) stamp;
}

From source file:Main.java

/**
 * //from www .  j  av  a2 s .c o 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";
}