Java TimeZone Usage buildTimezone(int hours, int minutes)

Here you can find the source of buildTimezone(int hours, int minutes)

Description

Builds a timezone object with the given offset.

License

Open Source License

Parameter

Parameter Description
hours the hour offset
minutes the minute offset

Return

the timezone object

Declaration

public static TimeZone buildTimezone(int hours, int minutes) 

Method Source Code

//package com.java2s;

import java.util.SimpleTimeZone;
import java.util.TimeZone;

public class Main {
    /**//from   w w  w.jav a2 s.c o m
     * Builds a timezone object with the given offset.
     * @param hours the hour offset
     * @param minutes the minute offset
     * @return the timezone object
     */
    public static TimeZone buildTimezone(int hours, int minutes) {
        int hourMillis = 1000 * 60 * 60 * hours;

        int minuteMillis = 1000 * 60 * minutes;
        if (hours < 0) {
            minuteMillis *= -1;
        }

        return new SimpleTimeZone(hourMillis + minuteMillis, "");
    }
}

Related

  1. addGmtOffset(long millis)
  2. assertTimeZoneNotNull(String methodName, TimeZone timeZone)
  3. computeTimeZoneOffsetInHours(TimeZone timeZone, long currentDatetime)
  4. createPostgresTimeZone()
  5. createTaiTimeZone(int leapSecs)
  6. datePlusDays(Date date, int days)