本文整理匯總了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;
}