Java TimeZone getTimeZoneOffset(Date d)

Here you can find the source of getTimeZoneOffset(Date d)

Description

get Time Zone Offset

License

Open Source License

Declaration

public static int getTimeZoneOffset(Date d) 

Method Source Code

//package com.java2s;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.TimeZone;

public class Main {
    public static int getTimeZoneOffset(Date d) {
        Calendar c = getCalendar();
        c.setTime(d);//from ww  w. j a  v a  2  s.  c o  m
        return (c.get(Calendar.ZONE_OFFSET) + c.get(Calendar.DST_OFFSET));
    }

    /**
     * month ranges from 1 to 12 (not 0 to 11)
     */
    private static Calendar getCalendar() {
        return (getCalendar(null, null));
    }

    private static Calendar getCalendar(TimeZone timeZone, Locale locale) {
        if (timeZone == null)
            timeZone = TimeZone.getDefault();

        if (locale == null)
            locale = Locale.getDefault();

        Calendar c = new GregorianCalendar(timeZone, locale);
        return (c);
    }

    public static Date setTime(Date d, long time) {
        d.setTime(time);
        return (d);
    }
}

Related

  1. getDateValue(TimeZone zone, Long dateBoxValue, Long timeBoxValue)
  2. getDateWithoutTimeZone(Date date)
  3. getExcelSerialDayNumber(Date date, Locale locale, TimeZone timeZone)
  4. getLocalTime( java.util.TimeZone localTimeZone, java.util.Date timestamp, java.util.TimeZone sourceTimeZone)
  5. getTimezoneDate(String stateCode)
  6. getTimezoneOffsetInHours(Date date)
  7. hasTimeComponent(Date date, TimeZone timeZone)
  8. midnight(Date date, TimeZone tz)
  9. monthOfYear(Date referenceDate, int month, TimeZone timeZone)