本文整理了Java中java.util.TimeZone.getRawOffset()
方法的一些代码示例,展示了TimeZone.getRawOffset()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TimeZone.getRawOffset()
方法的具体详情如下:
包路径:java.util.TimeZone
类名称:TimeZone
方法名:getRawOffset
[英]Returns the amount of time in milliseconds to add to UTC to get standard time in this time zone. Because this value is not affected by daylight saving time, it is called raw offset.
If an underlying TimeZone
implementation subclass supports historical GMT offset changes, the method returns the raw offset value of the current date. In Honolulu, for example, its raw offset changed from GMT-10:30 to GMT-10:00 in 1947, and this method always returns -36000000 milliseconds (i.e., -10 hours).
[中]返回要添加到UTC以获取此时区的标准时间的时间量(以毫秒为单位)。由于该值不受夏令时的影响,因此称为原始偏移。
如果基础TimeZone
实现子类支持历史GMT偏移量更改,则该方法返回当前日期的原始偏移量值。例如,在火奴鲁鲁,其原始偏移量在1947年从GMT-10:30更改为GMT-10:00,该方法始终返回-36000000毫秒(即-10小时)。
代码示例来源:origin: stackoverflow.com
import java.util.TimeZone;
public class Test {
public static void main(String[] args) throws Exception {
long startOf1900Utc = -2208988800000L;
for (String id : TimeZone.getAvailableIDs()) {
TimeZone zone = TimeZone.getTimeZone(id);
if (zone.getRawOffset() != zone.getOffset(startOf1900Utc - 1)) {
System.out.println(id);
}
}
}
}
代码示例来源:origin: redisson/redisson
/**
* Returns raw offset difference in milliseconds.
*/
public static int getRawOffsetDifference(TimeZone from, TimeZone to) {
int offsetBefore = from.getRawOffset();
int offsetAfter = to.getRawOffset();
return offsetAfter - offsetBefore;
}
代码示例来源:origin: robovm/robovm
/**
* Returns true if {@code timeZone} has the same rules as this time zone.
*
* <p>The base implementation returns true if both time zones have the same
* raw offset.
*/
public boolean hasSameRules(TimeZone timeZone) {
if (timeZone == null) {
return false;
}
return getRawOffset() == timeZone.getRawOffset();
}
代码示例来源:origin: jphp-group/jphp
@Override
public boolean __greaterEq(WrapTimeZone iObject) {
return this.timeZone.getRawOffset() >= iObject.timeZone.getRawOffset();
}
代码示例来源:origin: apache/geode
/**
* Returns the time zone used when the archive was created. This can be used to print timestamps
* in the same time zone that was in effect when the archive was created.
*/
public TimeZone getTimeZone() {
TimeZone result = TimeZone.getTimeZone(this.timeZoneName);
if (result.getRawOffset() != this.timeZoneOffset) {
result = new SimpleTimeZone(this.timeZoneOffset, this.timeZoneName);
}
return result;
}
代码示例来源:origin: redisson/redisson
/**
* Returns <code>true</code> if current date is in
* daylight savings time in the time zone.
*/
public boolean isInDaylightTime() {
long now = getTimeInMillis();
int offset = timezone.getOffset(now);
int rawOffset = timezone.getRawOffset();
return (offset != rawOffset);
}
代码示例来源:origin: traccar/traccar
@Override
public String formatValue(String key, Object value) {
if (key.equals(Command.KEY_TIMEZONE)) {
return String.valueOf(TimeZone.getTimeZone((String) value).getRawOffset() / 3600000);
}
return null;
}
代码示例来源:origin: stackoverflow.com
Calendar mCalendar = new GregorianCalendar();
TimeZone mTimeZone = mCalendar.getTimeZone();
int mGMTOffset = mTimeZone.getRawOffset();
System.out.printf("GMT offset is %s hours", TimeUnit.HOURS.convert(mGMTOffset, TimeUnit.MILLISECONDS));
代码示例来源:origin: igniterealtime/Openfire
/**
* Formats a {@link TimeZone} as specified in XEP-0082: XMPP Date and Time Profiles.
*
* @param tz The time zone.
* @return The formatted time zone.
*/
String formatsTimeZone(TimeZone tz) {
// package-private for test.
int seconds = Math.abs(tz.getOffset(System.currentTimeMillis())) / 1000;
int hours = seconds / 3600;
int minutes = (seconds % 3600) / 60;
return (tz.getRawOffset() < 0 ? "-" : "+") + String.format("%02d:%02d", hours, minutes);
}
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* {@inheritDoc}
*/
@Override
void setCalendar(final FastDateParser parser, final Calendar cal, final String timeZone) {
final TimeZone tz = FastTimeZone.getGmtTimeZone(timeZone);
if (tz != null) {
cal.setTimeZone(tz);
} else {
final String lowerCase = timeZone.toLowerCase(locale);
TzInfo tzInfo = tzNames.get(lowerCase);
if (tzInfo == null) {
// match missing the optional trailing period
tzInfo = tzNames.get(lowerCase + '.');
}
cal.set(Calendar.DST_OFFSET, tzInfo.dstOffset);
cal.set(Calendar.ZONE_OFFSET, tzInfo.zone.getRawOffset());
}
}
}
代码示例来源:origin: stackoverflow.com
Calendar cSchedStartCal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
long gmtTime = cSchedStartCal.getTime().getTime();
long timezoneAlteredTime = gmtTime + TimeZone.getTimeZone("Asia/Calcutta").getRawOffset();
Calendar cSchedStartCal1 = Calendar.getInstance(TimeZone.getTimeZone("Asia/Calcutta"));
cSchedStartCal1.setTimeInMillis(timezoneAlteredTime);
代码示例来源:origin: stackoverflow.com
Calendar c = Calendar.getInstance();
System.out.println("current: "+c.getTime());
TimeZone z = c.getTimeZone();
int offset = z.getRawOffset();
if(z.inDaylightTime(new Date())){
offset = offset + z.getDSTSavings();
}
int offsetHrs = offset / 1000 / 60 / 60;
int offsetMins = offset / 1000 / 60 % 60;
System.out.println("offset: " + offsetHrs);
System.out.println("offset: " + offsetMins);
c.add(Calendar.HOUR_OF_DAY, (-offsetHrs));
c.add(Calendar.MINUTE, (-offsetMins));
System.out.println("GMT Time: "+c.getTime());
代码示例来源:origin: traccar/traccar
@Override
public String formatValue(String key, Object value) {
if (key.equals(Command.KEY_TIMEZONE)) {
double offset = TimeZone.getTimeZone((String) value).getRawOffset() / 3600000.0;
DecimalFormat fmt = new DecimalFormat("+#.##;-#.##", DecimalFormatSymbols.getInstance(Locale.US));
return fmt.format(offset);
} else if (key.equals(Command.KEY_MESSAGE)) {
return DataConverter.printHex(value.toString().getBytes(StandardCharsets.UTF_16BE));
}
return null;
}
代码示例来源:origin: robovm/robovm
@Override
protected void computeFields() {
TimeZone timeZone = getTimeZone();
int dstOffset = timeZone.inDaylightTime(new Date(time)) ? timeZone.getDSTSavings() : 0;
int zoneOffset = timeZone.getRawOffset();
fields[DST_OFFSET] = dstOffset;
fields[ZONE_OFFSET] = zoneOffset;
fullFieldsCalc(time, zoneOffset);
for (int i = 0; i < FIELD_COUNT; i++) {
isSet[i] = true;
}
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testHoursColonMinutes() {
assertEquals(HOURS_23, FastTimeZone.getGmtTimeZone("23:00").getRawOffset());
assertEquals(HOURS_2, FastTimeZone.getGmtTimeZone("2:00").getRawOffset());
assertEquals(MINUTES_59, FastTimeZone.getGmtTimeZone("00:59").getRawOffset());
assertEquals(MINUTES_5, FastTimeZone.getGmtTimeZone("00:5").getRawOffset());
assertEquals(HOURS_23+MINUTES_59, FastTimeZone.getGmtTimeZone("23:59").getRawOffset());
assertEquals(HOURS_2+MINUTES_5, FastTimeZone.getGmtTimeZone("2:5").getRawOffset());
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testHoursMinutes() {
assertEquals(HOURS_23, FastTimeZone.getGmtTimeZone("2300").getRawOffset());
assertEquals(HOURS_2, FastTimeZone.getGmtTimeZone("0200").getRawOffset());
assertEquals(MINUTES_59, FastTimeZone.getGmtTimeZone("0059").getRawOffset());
assertEquals(MINUTES_5, FastTimeZone.getGmtTimeZone("0005").getRawOffset());
assertEquals(HOURS_23+MINUTES_59, FastTimeZone.getGmtTimeZone("2359").getRawOffset());
assertEquals(HOURS_2+MINUTES_5, FastTimeZone.getGmtTimeZone("0205").getRawOffset());
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testSign() {
assertEquals(HOURS_23, FastTimeZone.getGmtTimeZone("+23:00").getRawOffset());
assertEquals(HOURS_2, FastTimeZone.getGmtTimeZone("+2:00").getRawOffset());
assertEquals(-HOURS_23, FastTimeZone.getGmtTimeZone("-23:00").getRawOffset());
assertEquals(-HOURS_2, FastTimeZone.getGmtTimeZone("-2:00").getRawOffset());
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testGmtPrefix() {
assertEquals(HOURS_23, FastTimeZone.getGmtTimeZone("GMT+23:00").getRawOffset());
assertEquals(-HOURS_23, FastTimeZone.getGmtTimeZone("GMT-23:00").getRawOffset());
}
代码示例来源:origin: jphp-group/jphp
@Signature
public Memory __debugInfo(Environment env, Memory... args) {
ArrayMemory r = new ArrayMemory();
r.refOfIndex("*id").assign(timeZone.getID());
r.refOfIndex("*rawOffset").assign(timeZone.getRawOffset());
r.refOfIndex("*name").assign(timeZone.getDisplayName());
return r.toConstant();
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testGetGmtTimeZone() {
assertEquals(0, FastTimeZone.getGmtTimeZone().getRawOffset());
}
内容来源于网络,如有侵权,请联系作者删除!