java.util.TimeZone.setRawOffset()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.4k)|赞(0)|评价(0)|浏览(108)

本文整理了Java中java.util.TimeZone.setRawOffset()方法的一些代码示例,展示了TimeZone.setRawOffset()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TimeZone.setRawOffset()方法的具体详情如下:
包路径:java.util.TimeZone
类名称:TimeZone
方法名:setRawOffset

TimeZone.setRawOffset介绍

[英]Sets the base time zone offset to GMT. This is the offset to add to UTC to get local time.

If an underlying TimeZone implementation subclass supports historical GMT offset changes, the specified GMT offset is set as the latest GMT offset and the difference from the known latest GMT offset value is used to adjust all historical GMT offset values.
[中]将基本时区偏移设置为GMT。这是要添加到UTC以获取本地时间的偏移。
如果基础TimeZone实现子类支持历史GMT偏移量更改,则指定的GMT偏移量将设置为最新的GMT偏移量,并使用与已知的最新GMT偏移量值的差异来调整所有历史GMT偏移量值。

代码示例

代码示例来源:origin: traccar/traccar

protected TimeZone getTimeZone(long deviceId, String defaultTimeZone) {
  TimeZone result = TimeZone.getTimeZone(defaultTimeZone);
  String timeZoneName = identityManager.lookupAttributeString(deviceId, "decoder.timezone", null, true);
  if (timeZoneName != null) {
    result = TimeZone.getTimeZone(timeZoneName);
  } else {
    int timeZoneOffset = config.getInteger(getProtocolName() + ".timezone", 0);
    if (timeZoneOffset != 0) {
      result.setRawOffset(timeZoneOffset * 1000);
      LOGGER.warn("Config parameter " + getProtocolName() + ".timezone is deprecated");
    }
  }
  return result;
}

代码示例来源:origin: traccar/traccar

TimeZone timeZone = deviceSession.getTimeZone();
if (timeZone.getRawOffset() == 0) {
  timeZone.setRawOffset(offset * 1000);
  deviceSession.setTimeZone(timeZone);

代码示例来源:origin: apache/pdfbox

tz.setRawOffset(restrainTZoffset(hrSign * (tzHours * MILLIS_PER_HOUR + tzMin *
                      (long) MILLIS_PER_MINUTE)));
updateZoneId(tz);

代码示例来源:origin: org.jboss.seam/jboss-seam

@Override
public void setRawOffset(int offset) {
 timeZone.setRawOffset(offset);
}

代码示例来源:origin: at.bestsolution.efxclipse.eclipse/com.ibm.icu.base

/**
 * Sets the base time zone offset to GMT.
 * This is the offset to add *to* UTC to get local time.
 * @param offsetMillis the given base time zone offset to GMT.
 * @stable ICU 2.0
 */
public void setRawOffset(int offsetMillis) {
  if (isFrozen) {
    throw new UnsupportedOperationException("Attempt to modify a frozen TimeZone instance.");
  }
  timeZone.setRawOffset(offsetMillis);
}

代码示例来源:origin: at.bestsolution.eclipse/com.ibm.icu.base

/**
 * Sets the base time zone offset to GMT.
 * This is the offset to add *to* UTC to get local time.
 * @param offsetMillis the given base time zone offset to GMT.
 * @stable ICU 2.0
 */
public void setRawOffset(int offsetMillis) {
  if (isFrozen) {
    throw new UnsupportedOperationException("Attempt to modify a frozen TimeZone instance.");
  }
  timeZone.setRawOffset(offsetMillis);
}

代码示例来源:origin: org.n52.security/52n-security-core

/**
 * Creates UTC Timezone with given offset in millisec.
 */
public static TimeZone createUTCTimeZone(int offset) {
  TimeZone zone = TimeZone.getTimeZone("UTC");
  if (offset != 0) {
    zone.setRawOffset(offset);
  }
  return zone;
}

代码示例来源:origin: stackoverflow.com

DateFormat dateFormat = new SimpleDateFormat("MMM dd, yyyy hh:mm aa zzz");
 TimeZone defaultTimeZone = TimeZone.getDefault();
 TimeZone timeZone = TimeZone.getTimeZone("");
 timeZone.setID(defaultTimeZone.getID());
 timeZone.setRawOffset(defaultTimeZone.getRawOffset());
 dateFormat.setTimeZone(timeZone);
 System.out.println(dateFormat.format(new Date(1243861200000L)));

代码示例来源:origin: graphstream/gs-core

public void set(String value, Calendar calendar) {
  if (value.equals("Z")) {
    calendar.getTimeZone().setRawOffset(0);
  } else {
    String hs = value.substring(1, 3);
    String ms = value.substring(3, 5);
    if (hs.charAt(0) == '0')
      hs = hs.substring(1);
    if (ms.charAt(0) == '0')
      ms = ms.substring(1);
    int i = value.charAt(0) == '+' ? 1 : -1;
    int h = Integer.parseInt(hs);
    int m = Integer.parseInt(ms);
    calendar.getTimeZone().setRawOffset(i * (h * 60 + m) * 60000);
  }
}

代码示例来源:origin: com.ibm.icu/icu4j-localespi

@Override
public void setRawOffset(int offsetMillis) {
  if (isFrozen()) {
    throw new UnsupportedOperationException("Attempt to modify a frozen TimeZoneJDK instance.");
  }
  fJdkTz.setRawOffset(offsetMillis);
}

代码示例来源:origin: io.virtdata/virtdata-lib-realer

@Override
public void setRawOffset(int offsetMillis) {
  if (isFrozen()) {
    throw new UnsupportedOperationException("Attempt to modify a frozen JavaTimeZone instance.");
  }
  javatz.setRawOffset(offsetMillis);
}

代码示例来源:origin: org.graphstream/gs-core

public void set(String value, Calendar calendar) {
  if (value.equals("Z")) {
    calendar.getTimeZone().setRawOffset(0);
  } else {
    String hs = value.substring(1, 3);
    String ms = value.substring(3, 5);
    if (hs.charAt(0) == '0')
      hs = hs.substring(1);
    if (ms.charAt(0) == '0')
      ms = ms.substring(1);
    int i = value.charAt(0) == '+' ? 1 : -1;
    int h = Integer.parseInt(hs);
    int m = Integer.parseInt(ms);
    calendar.getTimeZone().setRawOffset(i * (h * 60 + m) * 60000);
  }
}

代码示例来源:origin: org.n52.security/52n-security-core

/**
 * Method formats a date to an iso formated string.
 * It will always produce the full iso format, e.g.: 2009-11-17T13:28:17.235+0100.
 * 
 * @param date
 *            the date.
 * @return String.
 */
public static String tofullISOString(final Date date) {
  TimeZone zone = TimeZone.getTimeZone("UTC");
  zone.setRawOffset(-date.getTimezoneOffset() * 60 * 1000);
  Calendar cal = Calendar.getInstance(zone);
  cal.setTime(date);
  return tofullISOString(cal);
}

代码示例来源:origin: org.pageseeder.flint/pso-flint-lucene

/**
 * Format the value as an ISO8601 date time.
 *
 * @param value       the value from the index
 * @param offset      the timezone offset (adjust for the specified offset)
 *
 * @return the corresponding value.
 *
 * @throws ParseException if the value is not a parseable date.
 */
public static synchronized String toISODateTime(String value, int offset) throws ParseException {
 int x = findNonDigitCharacter(value);
 if (x != -1) throw new ParseException("Value is not a valid Lucene date", x);
 Date date = DateTools.stringToDate(value);
 // Only adjust for day light savings...
 TimeZone tz = TimeZone.getDefault();
 int rawOffset = tz.inDaylightTime(date)? offset - ONE_HOUR_IN_MS : offset;
 tz.setRawOffset(rawOffset);
 ISO_DATETIME.setTimeZone(tz);
 String formatted = ISO_DATETIME.format(date);
 // the Java timezone does not include the required ':'
 return formatted.substring(0, formatted.length() - 2) + ":" + formatted.substring(formatted.length() - 2);
}

代码示例来源:origin: com.haulmont.thirdparty/eclipselink

/**
 * Build a calendar from TIMESTAMPTZWrapper. 
 */
public static Calendar buildCalendar(TIMESTAMPTZWrapper timestampTZ) throws SQLException{
  Timestamp ts = timestampTZ.getTimestamp();
  TimeZone tz = timestampTZ.getTimeZone();
  Calendar gCal;
  if(timestampTZ.isTimestampInGmt()) {
    gCal = Calendar.getInstance(tz);
    gCal.setTime(ts);
  } else {
    gCal = Calendar.getInstance();
    gCal.setTime(ts);
    gCal.getTimeZone().setID(tz.getID());
    gCal.getTimeZone().setRawOffset(tz.getRawOffset());
  }
  return gCal;
}

代码示例来源:origin: org.eclipse.persistence/org.eclipse.persistence.oracle

/**
 * Build a calendar from TIMESTAMPTZWrapper.
 */
public static Calendar buildCalendar(TIMESTAMPTZWrapper timestampTZ) throws SQLException{
  Timestamp ts = timestampTZ.getTimestamp();
  TimeZone tz = timestampTZ.getTimeZone();
  Calendar gCal;
  if(timestampTZ.isTimestampInGmt()) {
    gCal = Calendar.getInstance(tz);
    gCal.setTime(ts);
  } else {
    gCal = Calendar.getInstance();
    gCal.setTime(ts);
    gCal.getTimeZone().setID(tz.getID());
    gCal.getTimeZone().setRawOffset(tz.getRawOffset());
  }
  return gCal;
}

代码示例来源:origin: org.apache.pdfbox/pdfbox

tz.setRawOffset(restrainTZoffset(hrSign * (tzHours * MILLIS_PER_HOUR + tzMin *
                      (long) MILLIS_PER_MINUTE)));
updateZoneId(tz);

代码示例来源:origin: TomRoush/PdfBox-Android

tz.setRawOffset(restrainTZoffset(hrSign * (tzHours * MILLIS_PER_HOUR + tzMin *
                      (long) MILLIS_PER_MINUTE)));
tz.setID("unknown");

代码示例来源:origin: com.github.lafa.pdfbox/pdfbox

tz.setRawOffset(restrainTZoffset(hrSign * (tzHours * MILLIS_PER_HOUR + tzMin *
                      (long) MILLIS_PER_MINUTE)));
updateZoneId(tz);

代码示例来源:origin: locationtech/geogig

DATE_FORMAT.getCalendar().getTimeZone().setRawOffset(timeZoneOffset);
String formattedDate = DATE_FORMAT.format(timestamp);

相关文章