Java TimeUnit Usage getTimezoneOffset(TimeZone timeZone)

Here you can find the source of getTimezoneOffset(TimeZone timeZone)

Description

get Timezone Offset

License

Apache License

Declaration

public static String getTimezoneOffset(TimeZone timeZone) 

Method Source Code

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

import java.util.TimeZone;
import java.util.concurrent.TimeUnit;

public class Main {
    public static String getTimezoneOffset(TimeZone timeZone) {
        long hours = TimeUnit.MILLISECONDS.toHours(timeZone.getRawOffset());
        long minutes = TimeUnit.MILLISECONDS.toMinutes(timeZone.getRawOffset()) - TimeUnit.HOURS.toMinutes(hours);

        minutes = Math.abs(minutes);

        String result = "";

        if (hours > 0) {
            result = String.format("GMT+%d:%02d %s", hours, minutes, timeZone.getID());
        } else {/*from  ww  w  .  j av  a  2  s  .c  o  m*/
            result = String.format("GMT%d:%02d %s", hours, minutes, timeZone.getID());
        }

        return result;
    }
}

Related

  1. getTimeDifference(Date startDate, Date endDate)
  2. getTimeFormat(final long time)
  3. getTimeForS3URL()
  4. getTimeInMillis(String str)
  5. getTimeString(long millis)
  6. getTomorrowTimestamp()
  7. getUnit(long nanos)
  8. getValidityAsString(Date endDate)
  9. getWithTimeout(final Future future)