Example usage for java.util Calendar getTimeZone

List of usage examples for java.util Calendar getTimeZone

Introduction

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

Prototype

public TimeZone getTimeZone() 

Source Link

Document

Gets the time zone.

Usage

From source file:Main.java

public static void main(String[] args) {
    Calendar now = Calendar.getInstance();
    TimeZone timeZone = now.getTimeZone();
    System.out.println("Current TimeZone is : " + timeZone.getDisplayName());
}

From source file:Main.java

public static void main(String[] args) {

    Calendar cal = Calendar.getInstance();

    System.out.println(cal.getTimeZone().getDisplayName());

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

    // set the time zone with the given time zone value and print it
    cal.setTimeZone(tz);//from  w  w  w  .  j  av  a2  s .  c  o  m

    System.out.println(cal.getTimeZone().getDisplayName());
}

From source file:Main.java

public static void main(String[] args) {

    // create a calendar
    Calendar cal = Calendar.getInstance();

    // get the time zone
    TimeZone tz = cal.getTimeZone();

    // print the time zone name for this calendar
    System.out.println("The time zone is :" + tz.getDisplayName());

}

From source file:Main.java

public static void main(String[] args) {

    TimeZone tz1 = TimeZone.getTimeZone("GMT");
    Calendar cal1 = Calendar.getInstance(tz1);

    // display time zone for both calendars
    System.out.println("GMT: " + cal1.getTimeZone().getDisplayName());
}

From source file:Main.java

public static String getDeviceTimeZone() {
    Calendar calendar = Calendar.getInstance();
    TimeZone timeZone = calendar.getTimeZone();
    String retString = timeZone.getTimeZone(timeZone.getID()).getID();
    return retString;
}

From source file:Main.java

private static long currentTime() {
    Calendar time = Calendar.getInstance();
    time.add(Calendar.MILLISECOND, -time.getTimeZone().getOffset(time.getTimeInMillis()));
    return time.getTime().getTime();
}

From source file:Main.java

/**
 * Get formatted date string/*  ww  w  .  jav  a 2 s.c om*/
 */
public static String getFormattedDateString(Date date, String format) {
    Calendar cal = Calendar.getInstance();
    TimeZone timeZone = cal.getTimeZone();

    SimpleDateFormat dateFormat = new SimpleDateFormat(format);
    dateFormat.setTimeZone(timeZone);

    return dateFormat.format(date);
}

From source file:Main.java

/**
 * //from  w  w w .j av a 2s  .  c  om
 * @return
 */
public static long getMillisGMT() {
    Calendar calendar = new GregorianCalendar();
    TimeZone mTimeZone = calendar.getTimeZone();
    int offset = mTimeZone.getOffset(System.currentTimeMillis());
    return System.currentTimeMillis() - offset;
}

From source file:Main.java

/**
 * /*  w  w  w  .j a va2 s .c o  m*/
 * @return
 */
public static long getMillisGMT() {
    Calendar calendar = new GregorianCalendar();
    TimeZone mTimeZone = calendar.getTimeZone();
    int offset = mTimeZone.getRawOffset();
    return System.currentTimeMillis() - offset;
}

From source file:XSDDateTime.java

public static String getDateTime(Calendar cal) {
    if (!cal.getTimeZone().equals(TimeZone.getTimeZone("GMT+00:00"))) {
        throw new InvalidParameterException();
    }/*w w w  .ja v  a 2s. com*/
    int year = cal.get(Calendar.YEAR);
    int month = cal.get(Calendar.MONTH);
    month++;
    String monthString = pad(month);
    int day = cal.get(Calendar.DAY_OF_MONTH);
    String dayString = pad(day);
    int hour = cal.get(Calendar.HOUR_OF_DAY);
    String hourString = pad(hour);
    int minutes = cal.get(Calendar.MINUTE);
    String minutesString = pad(minutes);
    int seconds = cal.get(Calendar.SECOND);
    String secondsString = pad(seconds);

    return year + "-" + monthString + "-" + dayString + "T" + hourString + ":" + minutesString + ":"
            + secondsString + "Z";
}