📄 timezone.java
字号:
package com.jmobilecore.support;
/**
* The <code>TimeZone</code> represents a time zone offset and daylight savings.
*
* @author Greg Gridin
*/
public class TimeZone {
/**
* The list of available timezones
*/
static final protected String[] ids = {"WST", "MSK", "EET", "CET", "GMT", "AST", "EST", "CST", "MST", "PST", "AKST", "HST"};
/**
* Timezone's offsets
*/
static final protected int[] offsets = {8 * 60 * 60 * 1000, 3 * 60 * 60 * 1000,
2 * 60 * 60 * 1000, 1 * 60 * 60 * 1000,
0, -4 * 60 * 60 * 1000,
-5 * 60 * 60 * 1000, -6 * 60 * 60 * 1000,
-7 * 60 * 60 * 1000, -8 * 60 * 60 * 1000,
-9 * 60 * 60 * 1000, -10 * 60 * 60 * 1000};
/**
* The default timezone (GMT)
*
* @see #getDefault()
*/
static final protected TimeZone defTimeZone = new TimeZone("GMT", 0);
/**
* Gets all the available IDs supported.
*
* @return an array of <code>String</code> IDs.
*/
static public String[] getAvailableIDs() {
return ids;
}
/**
* Gets all the available offsets supported.
*
* @return an array of offsets.
* @see #getAvailableIDs()
*/
static public int[] getAvailableOffsets() {
return offsets;
}
/**
* Gets the default TimeZone.
*
* @see #defTimeZone
*/
static public TimeZone getDefault() {
return defTimeZone;
}
/**
* Gets the TimeZone for the given ID.
*
* @param timezone the ID for a TimeZone
* @return the specified TimeZone, or the GMT zone if the given timezone id cannot be understood
* @see #ids
*/
static public TimeZone getTimeZone(String timezone) {
int len = ids.length;
for (int i = 0; i < len; i++) {
if (ids[i].equals(timezone)) {
return new TimeZone(ids[i], offsets[i]);
}
}
return defTimeZone;
}
/**
* The current TimeZone id
*/
protected String id = "GMT";
/**
* The current TimeZone offset
*/
protected int offset = 0;
/**
* The current TimeZone daylight setting
*/
public boolean daylight = false;
/**
* Constructor for the TimeZone class
*
* @param id the TimeZone id
* @param offset the TimeZone offset
*/
protected TimeZone(String id, int offset) {
this.id = id;
this.offset = offset;
}
/**
* Gets the ID of this time zone.
*
* @return the ID of this time zone.
*/
public String getID() {
return id;
}
/**
* Gets the time zone offset, for current date, modified in case of daylight savings.
* This is the offset to add to UTC to get local time.
*
* @param era the era of the given date.
* @param year the year in the given date.
* @param month the month in the given date. Month is 0-based. e.g., 0 for January.
* @param day the day-in-month of the given date.
* @param dayOfWeek the day-of-week of the given date.
* @param millis the milliseconds in day in standard local time.
* @return the offset in milliseconds to add to GMT to get local time.
*/
public int getOffset(int era, int year, int month, int day, int dayOfWeek, int millis) {
return getRawOffset() + (daylight ? 60 * 60 * 1000 : 0);
}
/**
* Gets if this time zone uses daylight savings time.
*
* @return true if this time zone uses daylight savings time, false, otherwise.
*/
public boolean useDaylightTime() {
return true;
}
/**
* Returns the amount of time in milliseconds to add to UTC to get standard time in this time zone.
* Because this value is not affected by daylight saving time, it is called raw offset.
*
* @return the amount of raw offset time in milliseconds to add to UTC.
*/
public int getRawOffset() {
return offset;
}
} // class TimeZone
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -