Java TimeZone Get getTimezoneTime(long time, int timezone)

Here you can find the source of getTimezoneTime(long time, int timezone)

Description

get Timezone Time

License

Apache License

Declaration

public static long getTimezoneTime(long time, int timezone) 

Method Source Code

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

import java.util.Calendar;
import java.util.TimeZone;

public class Main {
    public static long getTimezoneTime(long time, int timezone) {

        Calendar calendar = getCalendar(time);
        int hour = calendar.get(Calendar.HOUR_OF_DAY);

        hour = (hour + timezone) % 24;/*from www  .j a va  2 s . c om*/
        if (hour < 0) {
            hour = 24 + hour;
            calendar.add(Calendar.DAY_OF_MONTH, -1);
        }

        calendar.set(Calendar.HOUR_OF_DAY, hour);
        return calendar.getTimeInMillis();
    }

    public static Calendar getCalendar() {

        return Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    }

    public static Calendar getCalendar(long time) {

        Calendar calendar = getCalendar();
        calendar.setTimeInMillis(time);
        return calendar;
    }
}

Related

  1. getTimeZoneID()
  2. getTimeZoneIDs()
  3. getTimeZoneOffset()
  4. getTimeZoneOffset(long t)
  5. getTimezones()
  6. isValidTimeZoneId(String timeZoneId)