Java Day From getServerOffset(boolean useDaylightSavingTime)

Here you can find the source of getServerOffset(boolean useDaylightSavingTime)

Description

get Server Offset

License

Apache License

Declaration

public static int getServerOffset(boolean useDaylightSavingTime) 

Method Source Code

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

import java.util.*;

public class Main {
    public static int getServerOffset(boolean useDaylightSavingTime) {
        boolean observingDaylightSavingTime = false;
        final int DST = 1;

        // New calendar to use as a reference point.
        Calendar today = new GregorianCalendar();

        // TimeZone set to 'EST' for GMT comparison so we can determine the offset.
        TimeZone serverTimeZone = TimeZone.getTimeZone("America/New_York");

        // First getTime() returns date, the second getTime() converts that to milliseconds since the default date in java.
        int offsetMilliseconds = serverTimeZone.getOffset(today.getTime().getTime());

        // 3600000 = 1000 (ms in a sec) * 60 (sec in a min) * 60 (min in a hour)
        int offsetHours = (offsetMilliseconds / 3600000);

        // If server is on DST since our servers are EDT
        if (offsetHours == -4) {
            observingDaylightSavingTime = true;
        }// w  w w.  j  a v  a 2s  . c o  m

        if (observingDaylightSavingTime && useDaylightSavingTime) {
            offsetHours -= DST;
        }

        return offsetHours;
    }
}

Related

  1. getLastDay(Date date)
  2. getNextDay(Date startTime, int n)
  3. getNextDay(String date)
  4. getNoonOfDay(Date day)
  5. getPlusDay(String _oneDay, int _aFewDays)
  6. getTimeField(Date day, int field)
  7. isBusinessDay(int dateIntToCheck)
  8. isDefaultWorkingDay(Date date)
  9. isOneDayZeroPoint(Date date)