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 String getUserPhoneTimezone() {
    TimeZone timeZone = TimeZone.getDefault();

    timeZone = timeZone.getTimeZone(timeZone.getID());
    Date date = new Date();

    DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    df.setTimeZone(timeZone);//from   w  w w.  j  av  a2 s.c  o  m

    return df.format(date);
}

From source file:Main.java

public static TimeZone stringToTimeZone(String tzString) {

    return TimeZone.getTimeZone(tzString != null ? tzString : "");
}

From source file:Main.java

public static long adjustTimezoneOffset(long utcMillies) {
    TimeZone tz = TimeZone.getTimeZone("CET");
    long offset = tz.getOffset(new Date().getTime());
    return utcMillies + offset;
}

From source file:Main.java

public static Long generateTimeStamp() {
    Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    return calendar.getTimeInMillis() / 1000L;
}

From source file:Main.java

public static String getTime() {
    Date currentDate = Calendar.getInstance(TimeZone.getTimeZone("JST"), Locale.getDefault()).getTime();
    /**//  ww w.j  a  v a 2 s . c o  m
    SimpleDateFormat formatter = 
       new SimpleDateFormat("EEE MMM dd hh:mm:ss yyyy", 
                    Locale.getDefault());
     **/
    SimpleDateFormat formatter = new SimpleDateFormat("EEE MMM dd hh:mm:ss yyyy", Locale.getDefault());

    return formatter.format(currentDate);
}

From source file:Main.java

private static String getTimestamp() {
    Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));

    long secondsSince = calendar.getTimeInMillis() / 1000L;

    return "" + secondsSince;
}

From source file:Main.java

public static Calendar getEmptyCalendarGreenwich() {
    Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("Etc/Greenwich"));
    calendar.clear();/*from ww w.java2  s.c o  m*/
    return calendar;
}

From source file:Main.java

public static String getTimeString(long millitm) {
    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    cal.setTimeInMillis(millitm);/*from w w w.  ja  va2  s.c  om*/
    return (setZeroPad(cal.get(Calendar.HOUR)) + ":" + setZeroPad(cal.get(Calendar.MINUTE)) + ":"
            + setZeroPad(cal.get(Calendar.SECOND)));
}

From source file:Main.java

public static long interval(final Date date) {
    return (Calendar.getInstance(TimeZone.getTimeZone("GMT+08:00")).getTimeInMillis() - date.getTime()) / 1000;
}

From source file:Main.java

public static long getUTCTime() {
    Calendar cal = Calendar.getInstance();
    cal.setTimeZone(TimeZone.getTimeZone("gmt"));
    return cal.getTimeInMillis();
}