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 getPastTime(long seconds) {
    SimpleDateFormat gmtDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S'Z'");
    gmtDateFormat.setTimeZone(TimeZone.getTimeZone("GMT+4"));
    String s = gmtDateFormat.format(new Date(System.currentTimeMillis() - seconds * 1000));
    //Current Date Time in GMT
    System.out.println("Current Date and Time in GMT time zone: " + s);
    return s;//  w  w w.  j a va  2s .co  m
}

From source file:Main.java

public static SimpleDateFormat getEndDateTimeInTimezone(String timezone) {
    SimpleDateFormat format = new SimpleDateFormat("h:mm a");
    if (timezone == null || timezone.isEmpty()) {
        format.setTimeZone(TimeZone.getDefault());
    } else/* w w  w. j ava  2  s.c o  m*/
        format.setTimeZone(TimeZone.getTimeZone("GMT+" + timezone));
    return format;
}

From source file:Main.java

public static long getDayInUTC(long time) {
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(time);//  w w  w. jav a  2  s .c  o m
    cal.set(Calendar.HOUR, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    cal.setTimeZone(TimeZone.getTimeZone("UTC"));
    return cal.getTimeInMillis();
}

From source file:Main.java

public static String timestamp() {
    String timestamp = null;//  w  w w  . j a  va  2 s. c om
    Calendar cal = Calendar.getInstance();
    DateFormat dfm = new SimpleDateFormat("yyyy-MM-ddHH:mm:ss", Locale.US);
    dfm.setTimeZone(TimeZone.getTimeZone("GMT"));
    timestamp = dfm.format(cal.getTime());
    return timestamp;
}

From source file:Main.java

/**
 @param time input in milliseconds TODO: covert to seconds
 *//*from   www .ja  v a  2s  . c  o  m*/
public static String formatLocaleDate(Context context, long time) {
    java.text.DateFormat df = DateFormat.getMediumDateFormat(context);
    df.setTimeZone(TimeZone.getTimeZone("GMT"));
    return df.format(new Date(time));
}

From source file:Main.java

public static String formatISO8601(Date date, String format) {
    String result = "";
    if (date != null) {
        SimpleDateFormat dateFormat = new SimpleDateFormat(format);
        TimeZone timeZone = TimeZone.getTimeZone("UTC");
        dateFormat.setTimeZone(timeZone);
        try {//from  w ww .  j a  va  2s.c om
            result = dateFormat.format(date);
        } catch (Exception e) {
            e.printStackTrace();
            return result;
        }
    }
    return result;
}

From source file:Main.java

public static SimpleDateFormat getStartDateTimeInTimezone(String timezone) {
    SimpleDateFormat format = new SimpleDateFormat("EEEE, MMMM d, h:mm a");
    if (timezone == null || timezone.isEmpty()) {
        format.setTimeZone(TimeZone.getDefault());
    } else//from ww w  . j  a  va2s .  co m
        format.setTimeZone(TimeZone.getTimeZone("GMT+" + timezone));
    return format;
}

From source file:Main.java

public static SimpleDateFormat getServerDateTimeInTimezone(String timezone) {

    SimpleDateFormat format = new SimpleDateFormat("EEE, d MMM yyyy");
    if (timezone == null || timezone.isEmpty()) {
        format.setTimeZone(TimeZone.getDefault());
    } else {//from  w  w  w . j  a  va2 s  .  com
        format.setTimeZone(TimeZone.getTimeZone("GMT+" + timezone));
    }
    return format;
}

From source file:Main.java

/**
 * Gets Date with UTC time zone//w  w w.  ja  va 2 s  . co m
 *
 * @param date is concrete date
 * @return new instance calendar
 */
public static Calendar getCalendarUTC(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
    return calendar;
}

From source file:Main.java

public static String formatJsonDate(String jd) {
    sdfgmt.setTimeZone(TimeZone.getTimeZone("GMT"));
    sdfest.setTimeZone(TimeZone.getTimeZone("US/Eastern"));

    String stripped = jd.substring(0, 19).replace('T', ' ');
    Date date = new Date();

    try {/*from w ww .  j av a  2 s  .c  o  m*/
        date = sdfgmt.parse(stripped);
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    String result = sdfest.format(date);

    return result;
}