本文整理汇总了Java中java.util.TimeZone.getDSTSavings方法的典型用法代码示例。如果您正苦于以下问题:Java TimeZone.getDSTSavings方法的具体用法?Java TimeZone.getDSTSavings怎么用?Java TimeZone.getDSTSavings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.TimeZone
的用法示例。
在下文中一共展示了TimeZone.getDSTSavings方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDisplayNameArray
import java.util.TimeZone; //导入方法依赖的package包/类
private String[] getDisplayNameArray(String id, Locale locale) {
Objects.requireNonNull(id);
Objects.requireNonNull(locale);
String[] ret =
LocaleProviderAdapter.forType(type).getLocaleResources(locale).getTimeZoneNames(id);
if (Objects.nonNull(ret) && type == LocaleProviderAdapter.Type.CLDR) {
// check for CLDR's "no inheritance marker"
for (int index = 0; index < ret.length; index++) {
TimeZone tz = null;
if (CLDR_NO_INHERITANCE_MARKER.equals(ret[index])) {
if (Objects.isNull(tz)) {
tz = TimeZone.getTimeZone(id);
}
int offset = tz.getRawOffset();
if (index == 3 || index == 4) { // daylight
offset += tz.getDSTSavings();
}
ret[index] = ZoneInfoFile.toCustomID(offset);
}
}
}
return ret;
}
示例2: getTimeZone
import java.util.TimeZone; //导入方法依赖的package包/类
public static int getTimeZone() {
TimeZone tz = TimeZone.getDefault();
String displayName = tz.getDisplayName();
int dstSavings = tz.getDSTSavings();
String id = tz.getID();
String displayName2 = tz.getDisplayName(false, TimeZone.SHORT);
return 1;
}
示例3: createTimezoneDTO
import java.util.TimeZone; //导入方法依赖的package包/类
/**
* Returns new <code>Timezone</code> object with populated values.
*
* @param timeZone
* @param selected
* @return
*/
public static TimezoneDTO createTimezoneDTO(TimeZone timeZone, boolean selected) {
TimezoneDTO timezoneDTO = new TimezoneDTO();
timezoneDTO.timeZoneId = timeZone.getID();
int timeZoneRawOffset = timeZone.getRawOffset();
timezoneDTO.rawOffset = new Date(Math.abs(timeZoneRawOffset));
timezoneDTO.isRawOffsetNegative = timeZoneRawOffset < 0;
timezoneDTO.dstOffset = timeZone.getDSTSavings() / 60000;
timezoneDTO.displayName = timeZone.getDisplayName();
timezoneDTO.selected = selected;
return timezoneDTO;
}
示例4: subParseZoneString
import java.util.TimeZone; //导入方法依赖的package包/类
/**
* find time zone 'text' matched zoneStrings and set to internal
* calendar.
*/
private int subParseZoneString(String text, int start, CalendarBuilder calb) {
boolean useSameName = false; // true if standard and daylight time use the same abbreviation.
TimeZone currentTimeZone = getTimeZone();
// At this point, check for named time zones by looking through
// the locale data from the TimeZoneNames strings.
// Want to be able to parse both short and long forms.
int zoneIndex = formatData.getZoneIndex(currentTimeZone.getID());
TimeZone tz = null;
String[][] zoneStrings = formatData.getZoneStringsWrapper();
String[] zoneNames = null;
int nameIndex = 0;
if (zoneIndex != -1) {
zoneNames = zoneStrings[zoneIndex];
if ((nameIndex = matchZoneString(text, start, zoneNames)) > 0) {
if (nameIndex <= 2) {
// Check if the standard name (abbr) and the daylight name are the same.
useSameName = zoneNames[nameIndex].equalsIgnoreCase(zoneNames[nameIndex + 2]);
}
tz = TimeZone.getTimeZone(zoneNames[0]);
}
}
if (tz == null) {
zoneIndex = formatData.getZoneIndex(TimeZone.getDefault().getID());
if (zoneIndex != -1) {
zoneNames = zoneStrings[zoneIndex];
if ((nameIndex = matchZoneString(text, start, zoneNames)) > 0) {
if (nameIndex <= 2) {
useSameName = zoneNames[nameIndex].equalsIgnoreCase(zoneNames[nameIndex + 2]);
}
tz = TimeZone.getTimeZone(zoneNames[0]);
}
}
}
if (tz == null) {
int len = zoneStrings.length;
for (int i = 0; i < len; i++) {
zoneNames = zoneStrings[i];
if ((nameIndex = matchZoneString(text, start, zoneNames)) > 0) {
if (nameIndex <= 2) {
useSameName = zoneNames[nameIndex].equalsIgnoreCase(zoneNames[nameIndex + 2]);
}
tz = TimeZone.getTimeZone(zoneNames[0]);
break;
}
}
}
if (tz != null) { // Matched any ?
if (!tz.equals(currentTimeZone)) {
setTimeZone(tz);
}
// If the time zone matched uses the same name
// (abbreviation) for both standard and daylight time,
// let the time zone in the Calendar decide which one.
//
// Also if tz.getDSTSaving() returns 0 for DST, use tz to
// determine the local time. (6645292)
int dstAmount = (nameIndex >= 3) ? tz.getDSTSavings() : 0;
if (!(useSameName || (nameIndex >= 3 && dstAmount == 0))) {
calb.clear(Calendar.ZONE_OFFSET).set(Calendar.DST_OFFSET, dstAmount);
}
return (start + zoneNames[nameIndex].length());
}
return 0;
}
示例5: subParseZoneString
import java.util.TimeZone; //导入方法依赖的package包/类
/**
* find time zone 'text' matched zoneStrings and set to internal
* calendar.
*/
private int subParseZoneString(String text, int start, CalendarBuilder calb) {
boolean useSameName = false; // true if standard and daylight time use the same abbreviation.
TimeZone currentTimeZone = getTimeZone();
// At this point, check for named time zones by looking through
// the locale data from the TimeZoneNames strings.
// Want to be able to parse both short and long forms.
int zoneIndex = formatData.getZoneIndex(currentTimeZone.getID());
TimeZone tz = null;
String[][] zoneStrings = formatData.getZoneStringsWrapper();
String[] zoneNames = null;
int nameIndex = 0;
if (zoneIndex != -1) {
zoneNames = zoneStrings[zoneIndex];
if ((nameIndex = matchZoneString(text, start, zoneNames)) > 0) {
if (nameIndex <= 2) {
// Check if the standard name (abbr) and the daylight name are the same.
useSameName = zoneNames[nameIndex].equalsIgnoreCase(zoneNames[nameIndex + 2]);
}
tz = TimeZone.getTimeZone(zoneNames[0]);
}
}
if (tz == null) {
zoneIndex = formatData.getZoneIndex(TimeZone.getDefault().getID());
if (zoneIndex != -1) {
zoneNames = zoneStrings[zoneIndex];
if ((nameIndex = matchZoneString(text, start, zoneNames)) > 0) {
if (nameIndex <= 2) {
useSameName = zoneNames[nameIndex].equalsIgnoreCase(zoneNames[nameIndex + 2]);
}
tz = TimeZone.getTimeZone(zoneNames[0]);
}
}
}
if (tz == null) {
int len = zoneStrings.length;
for (int i = 0; i < len; i++) {
zoneNames = zoneStrings[i];
if ((nameIndex = matchZoneString(text, start, zoneNames)) > 0) {
if (nameIndex <= 2) {
useSameName = zoneNames[nameIndex].equalsIgnoreCase(zoneNames[nameIndex + 2]);
}
tz = TimeZone.getTimeZone(zoneNames[0]);
break;
}
}
}
if (tz != null) { // Matched any ?
if (!tz.equals(currentTimeZone)) {
setTimeZone(tz);
}
// If the time zone matched uses the same name
// (abbreviation) for both standard and daylight time,
// let the time zone in the Calendar decide which one.
//
// Also if tz.getDSTSaving() returns 0 for DST, use tz to
// determine the local time. (6645292)
int dstAmount = (nameIndex >= 3) ? tz.getDSTSavings() : 0;
if (!(useSameName || (nameIndex >= 3 && dstAmount == 0))) {
calb.clear(Calendar.ZONE_OFFSET).set(Calendar.DST_OFFSET, dstAmount);
}
return (start + zoneNames[nameIndex].length());
}
return -start;
}