本文整理汇总了Java中java.util.TimeZone.setID方法的典型用法代码示例。如果您正苦于以下问题:Java TimeZone.setID方法的具体用法?Java TimeZone.setID怎么用?Java TimeZone.setID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.TimeZone
的用法示例。
在下文中一共展示了TimeZone.setID方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createTimeZone
import java.util.TimeZone; //导入方法依赖的package包/类
/**
* Creates time zone with DST setting equal to New York (where the STG and Edugen QA servers are located)
*
* @param rawOffset - offset for time zone you want to create
* @return - modified TimeZone
*/
public static TimeZone createTimeZone(int rawOffset) {
TimeZone defaultTimeZone = TimeZone.getTimeZone("America/New_York");
TimeZone newCustomTimeZone = (TimeZone) defaultTimeZone.clone();
//set id is required because otherwise DateTimeZone.forTimeZone will take timezone by ID "America/New_York"
//and we will lose offset
newCustomTimeZone.setID("SeleniumTimeZone");
newCustomTimeZone.setRawOffset(rawOffset);
return newCustomTimeZone;
}
示例2: getFormattingTimeZone
import java.util.TimeZone; //导入方法依赖的package包/类
/**
* Override to represent the id of the TimeZone used by DateFormat as GMT
* offset value so that we always format Date based on GMTOffsetTimeZone style
* (z) instead of using standard short or long TimeZone names of Java, since
* these names are not available in client side JavaScript.
*/
@Override
protected TimeZone getFormattingTimeZone(TimeZone tZone, Date targetDate)
{
TimeZone zone = (TimeZone) tZone.clone();
// set the id as "GMT Sign Hours : Minutes"
StringBuilder zoneId = new StringBuilder(9);
int offset;
if (targetDate != null)
offset = zone.getOffset (targetDate.getTime());
else
offset = zone.getRawOffset();
if (offset < 0)
{
zoneId.append(_GMT_MINUS);
// abs value
offset = -offset;
} else
{
zoneId.append(_GMT_PLUS);
}
int hours = offset / _MILLIS_PER_HOUR;
if (hours < 10)
{
zoneId.append('0');
}
zoneId.append(hours);
zoneId.append(':');
int minutes = (offset % _MILLIS_PER_HOUR) / _MILLIS_PER_MINUTE;
if (minutes < 10)
{
zoneId.append('0');
}
zoneId.append(minutes);
zone.setID(zoneId.toString());
return zone;
}