本文整理了Java中java.util.TimeZone.hasSameRules()
方法的一些代码示例,展示了TimeZone.hasSameRules()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TimeZone.hasSameRules()
方法的具体详情如下:
包路径:java.util.TimeZone
类名称:TimeZone
方法名:hasSameRules
[英]Returns true if this zone has the same rule and offset as another zone. That is, if this zone differs only in ID, if at all. Returns false if the other zone is null.
[中]如果此区域与另一个区域具有相同的规则和偏移量,则返回true。也就是说,如果这个区域只在ID上不同,如果有的话。如果另一个区域为空,则返回false。
代码示例来源:origin: commons-validator/commons-validator
/**
* <p>Adjusts a Calendar's value to a different TimeZone.</p>
*
* @param value The value to adjust.
* @param timeZone The new time zone to use to adjust the Calendar to.
*/
public static void adjustToTimeZone(Calendar value, TimeZone timeZone) {
if (value.getTimeZone().hasSameRules(timeZone)) {
value.setTimeZone(timeZone);
} else {
int year = value.get(Calendar.YEAR);
int month = value.get(Calendar.MONTH);
int date = value.get(Calendar.DATE);
int hour = value.get(Calendar.HOUR_OF_DAY);
int minute = value.get(Calendar.MINUTE);
value.setTimeZone(timeZone);
value.set(year, month, date, hour, minute);
}
}
代码示例来源:origin: commons-validator/commons-validator
assertTrue("SAME: UTC = GMT", UTC.hasSameRules(GMT));
assertEquals("SAME: Check time (A)", calUTC.getTime(), calGMT.getTime());
assertFalse("SAME: Check GMT(A)", GMT.equals(calUTC.getTimeZone()));
代码示例来源:origin: at.bestsolution.eclipse/com.ibm.icu.base
/**
* Returns true if this zone has the same rule and offset as another zone.
* That is, if this zone differs only in ID, if at all. Returns false
* if the other zone is null.
* @param other the <code>TimeZone</code> object to be compared with
* @return true if the other zone is not null and is the same as this one,
* with the possible exception of the ID
* @stable ICU 2.0
*/
public boolean hasSameRules(TimeZone other) {
return timeZone.hasSameRules(other.timeZone);
}
代码示例来源:origin: at.bestsolution.efxclipse.eclipse/com.ibm.icu.base
/**
* Returns true if this zone has the same rule and offset as another zone.
* That is, if this zone differs only in ID, if at all. Returns false
* if the other zone is null.
* @param other the <code>TimeZone</code> object to be compared with
* @return true if the other zone is not null and is the same as this one,
* with the possible exception of the ID
* @stable ICU 2.0
*/
public boolean hasSameRules(TimeZone other) {
return timeZone.hasSameRules(other.timeZone);
}
代码示例来源:origin: ModeShape/modeshape
private static void adjustCalendarForTime( Calendar initial,
Calendar target ) {
assert initial != null;
if (initial.getTimeZone().hasSameRules(target.getTimeZone())) {
target.setTime(initial.getTime());
return;
}
target.clear();
for (int i = 0; i <= Calendar.MILLISECOND; i++) {
target.set(i, initial.get(i));
}
}
代码示例来源:origin: org.modeshape/modeshape-jdbc-local
private static void adjustCalendarForTime( Calendar initial,
Calendar target ) {
assert initial != null;
if (initial.getTimeZone().hasSameRules(target.getTimeZone())) {
target.setTime(initial.getTime());
return;
}
target.clear();
for (int i = 0; i <= Calendar.MILLISECOND; i++) {
target.set(i, initial.get(i));
}
}
代码示例来源:origin: ModeShape/modeshape
private static Calendar adjustCalendarForDate( Calendar initial,
Calendar target ) {
assert initial != null;
if (initial.getTimeZone().hasSameRules(target.getTimeZone())) {
target.setTime(initial.getTime());
return target;
}
Calendar ntarget = new GregorianCalendar(target.getTimeZone());
ntarget.setTimeInMillis(initial.getTimeInMillis());
return ntarget;
}
代码示例来源:origin: org.modeshape/modeshape-jdbc-local
private static Calendar adjustCalendarForDate( Calendar initial,
Calendar target ) {
assert initial != null;
if (initial.getTimeZone().hasSameRules(target.getTimeZone())) {
target.setTime(initial.getTime());
return target;
}
Calendar ntarget = new GregorianCalendar(target.getTimeZone());
ntarget.setTimeInMillis(initial.getTimeInMillis());
return ntarget;
}
代码示例来源:origin: hprose/hprose-java
private void init(Calendar calendar) {
TimeZone tz = calendar.getTimeZone();
if (!(tz.hasSameRules(TimeZoneUtil.DefaultTZ) || tz.hasSameRules(TimeZoneUtil.UTC))) {
tz = TimeZoneUtil.UTC;
Calendar c = (Calendar) calendar.clone();
c.setTimeZone(tz);
calendar = c;
}
this.year = calendar.get(Calendar.YEAR);
this.month = calendar.get(Calendar.MONTH) + 1;
this.day = calendar.get(Calendar.DAY_OF_MONTH);
this.hour = calendar.get(Calendar.HOUR_OF_DAY);
this.minute = calendar.get(Calendar.MINUTE);
this.second = calendar.get(Calendar.SECOND);
this.nanosecond = calendar.get(Calendar.MILLISECOND) * 1000000;
this.utc = tz.hasSameRules(TimeZoneUtil.UTC);
}
代码示例来源:origin: org.teiid.connectors/translator-jdbc
@Override
protected Calendar initialValue() {
if(this.timeZone != null && this.timeZone.trim().length() > 0) {
TimeZone tz = TimeZone.getTimeZone(this.timeZone);
if(!TimestampWithTimezone.getCalendar().getTimeZone().hasSameRules(tz)) {
return Calendar.getInstance(tz);
}
}
return Calendar.getInstance();
}
};
代码示例来源:origin: org.teiid.connectors/translator-odata
@Override
public void start() throws TranslatorException {
super.start();
if(this.databaseTimeZone != null && this.databaseTimeZone.trim().length() > 0) {
TimeZone tz = TimeZone.getTimeZone(this.databaseTimeZone);
if(!DEFAULT_TIME_ZONE.hasSameRules(tz)) {
this.timeZone = tz;;
}
}
}
代码示例来源:origin: com.ibm.icu/icu4j-localespi
@Override
public boolean hasSameRules(java.util.TimeZone other) {
return other.hasSameRules(TimeZoneICU.wrap(fIcuTz));
}
代码示例来源:origin: ModeShape/modeshape
private static Calendar adjustCalendarForTimeStamp( Calendar initial,
Calendar target ) {
assert initial != null;
if (initial.getTimeZone().hasSameRules(target.getTimeZone())) {
target.setTime(initial.getTime());
return target;
}
TimeZone targetTimeZone = target.getTimeZone();
Calendar ret = new GregorianCalendar(targetTimeZone);
ret.setTimeInMillis(initial.getTimeInMillis() + targetTimeZone.getOffset(initial.getTimeInMillis())
- initial.getTimeZone().getOffset(initial.getTimeInMillis()));
ret.getTime();
return ret;
}
}
代码示例来源:origin: org.modeshape/modeshape-jdbc-local
private static Calendar adjustCalendarForTimeStamp( Calendar initial,
Calendar target ) {
assert initial != null;
if (initial.getTimeZone().hasSameRules(target.getTimeZone())) {
target.setTime(initial.getTime());
return target;
}
TimeZone targetTimeZone = target.getTimeZone();
Calendar ret = new GregorianCalendar(targetTimeZone);
ret.setTimeInMillis(initial.getTimeInMillis() + targetTimeZone.getOffset(initial.getTimeInMillis())
- initial.getTimeZone().getOffset(initial.getTimeInMillis()));
ret.getTime();
return ret;
}
}
代码示例来源:origin: hprose/hprose-java
@Override
public final void serialize(Writer writer, Calendar calendar) throws IOException {
super.serialize(writer, calendar);
TimeZone tz = calendar.getTimeZone();
if (!(tz.hasSameRules(TimeZoneUtil.DefaultTZ) || tz.hasSameRules(TimeZoneUtil.UTC))) {
tz = TimeZoneUtil.UTC;
Calendar c = (Calendar) calendar.clone();
c.setTimeZone(tz);
calendar = c;
}
OutputStream stream = writer.stream;
ValueWriter.writeDateOfCalendar(stream, calendar);
ValueWriter.writeTimeOfCalendar(stream, calendar, true, false);
stream.write(tz.hasSameRules(TimeZoneUtil.UTC) ? TagUTC : TagSemicolon);
}
}
代码示例来源:origin: zycgit/hasor
@Override
public final void serialize(Writer writer, Calendar calendar) throws IOException {
super.serialize(writer, calendar);
TimeZone tz = calendar.getTimeZone();
if (!(tz.hasSameRules(TimeZoneUtil.DefaultTZ) || tz.hasSameRules(TimeZoneUtil.UTC))) {
tz = TimeZoneUtil.UTC;
Calendar c = (Calendar) calendar.clone();
c.setTimeZone(tz);
calendar = c;
}
OutputStream stream = writer.stream;
ValueWriter.writeDateOfCalendar(stream, calendar);
ValueWriter.writeTimeOfCalendar(stream, calendar, true, false);
stream.write(tz.hasSameRules(TimeZoneUtil.UTC) ? HproseTags.TagUTC : HproseTags.TagSemicolon);
}
}
代码示例来源:origin: org.hprose/hprose-java
@Override
public final void serialize(Writer writer, Calendar calendar) throws IOException {
super.serialize(writer, calendar);
TimeZone tz = calendar.getTimeZone();
if (!(tz.hasSameRules(TimeZoneUtil.DefaultTZ) || tz.hasSameRules(TimeZoneUtil.UTC))) {
tz = TimeZoneUtil.UTC;
Calendar c = (Calendar) calendar.clone();
c.setTimeZone(tz);
calendar = c;
}
OutputStream stream = writer.stream;
ValueWriter.writeDateOfCalendar(stream, calendar);
ValueWriter.writeTimeOfCalendar(stream, calendar, true, false);
stream.write(tz.hasSameRules(TimeZoneUtil.UTC) ? TagUTC : TagSemicolon);
}
}
代码示例来源:origin: rombert/ereviewboard
Date getDateValueFromString(String attributeValue) {
Date parsedDateValue = parseDateValue(attributeValue);
TimeZone siteTimeZone = reviewboardClientData.getTimeZone();
if ( parsedDateValue == null || siteTimeZone == null || targetTimeZone.hasSameRules(siteTimeZone))
return parsedDateValue;
long localOffset = this.targetTimeZone.getOffset(parsedDateValue.getTime());
long siteOffset = siteTimeZone.getOffset(parsedDateValue.getTime());
return new Date(parsedDateValue.getTime() + ( localOffset - siteOffset ));
}
代码示例来源:origin: stackoverflow.com
TimeZone customTimeZone = TimeZone.getTimeZone("GMT-07:00");
TimeZone officialTimeZone = null;
for (String timeZoneId : TimeZone.getAvailableIDs()) {
if (TimeZone.getTimeZone(timeZoneId).hasSameRules(customTimeZone)){
officialTimeZone = TimeZone.getTimeZone(timeZoneId);
break;
}
}
ZoneRules zoneRules = ZoneRulesProvider.getRules(officialTimeZone.toZoneId().getId(), true);
System.out.println(zoneRules);
代码示例来源:origin: org.teiid/teiid-client
/**
* <p>MMPreparedStatement constructor.
* @param Driver's connection object.
* @param String object representing the prepared statement
*/
PreparedStatementImpl(ConnectionImpl connection, String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
super(connection, resultSetType, resultSetConcurrency);
if (sql == null) {
throw new TeiidSQLException(JDBCPlugin.Util.getString("MMPreparedStatement.Err_prep_sql")); //$NON-NLS-1$
}
this.prepareSql = sql;
TimeZone timezone = connection.getServerConnection().getLogonResult().getTimeZone();
if (timezone != null && !timezone.hasSameRules(getDefaultCalendar().getTimeZone())) {
this.serverCalendar = Calendar.getInstance(timezone);
}
}
内容来源于网络,如有侵权,请联系作者删除!