當前位置: 首頁>>代碼示例>>Java>>正文


Java TimeZone.clone方法代碼示例

本文整理匯總了Java中java.util.TimeZone.clone方法的典型用法代碼示例。如果您正苦於以下問題:Java TimeZone.clone方法的具體用法?Java TimeZone.clone怎麽用?Java TimeZone.clone使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.TimeZone的用法示例。


在下文中一共展示了TimeZone.clone方法的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;
}
 
開發者ID:WileyLabs,項目名稱:teasy,代碼行數:17,代碼來源:DateUtils.java

示例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;
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:49,代碼來源:DateTimeConverter.java


注:本文中的java.util.TimeZone.clone方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。