Java TimeZone Get getCurrentTimezoneOffset()

Here you can find the source of getCurrentTimezoneOffset()

Description

get Current Timezone Offset

License

Apache License

Declaration

public static String getCurrentTimezoneOffset() 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.*;

public class Main {

    public static String getCurrentTimezoneOffset() {

        TimeZone tz = TimeZone.getDefault();
        Calendar cal = GregorianCalendar.getInstance(tz);
        int offsetInMillis = tz.getOffset(cal.getTimeInMillis());

        String offset = String.format("%02d:%02d", Math.abs(offsetInMillis / 3600000),
                Math.abs((offsetInMillis / 60000) % 60));
        offset = (offsetInMillis >= 0 ? "+" : "-") + offset;

        return offset;
    }//from  ww  w.ja v a2 s .  com
}

Related

  1. getCalendarForTimeZone(final String timeZone)
  2. getCalendarInstance(TimeZone timeZone, Locale locale)
  3. getConvertDateString(Date date, TimeZone tz, String fmt)
  4. getCurrentCalendarInTimeZone(final TimeZone timeZone)
  5. getCurrentTimeZone()
  6. getDateInTimeZone(final Date date, final TimeZone timeZone)
  7. getDefaultTimeZoneOffset()
  8. getDefaultTimeZoneRawOffset()
  9. getDefaultTimeZoneString()