本文整理汇总了Java中java.util.TimeZone.equals方法的典型用法代码示例。如果您正苦于以下问题:Java TimeZone.equals方法的具体用法?Java TimeZone.equals怎么用?Java TimeZone.equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.TimeZone
的用法示例。
在下文中一共展示了TimeZone.equals方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: formatWithTimeZone
import java.util.TimeZone; //导入方法依赖的package包/类
protected String formatWithTimeZone(
String template,
Object[] arguments,
Locale locale,
TimeZone timezone)
{
MessageFormat mf = new MessageFormat(" ");
mf.setLocale(locale);
mf.applyPattern(template);
if (!timezone.equals(TimeZone.getDefault()))
{
Format[] formats = mf.getFormats();
for (int i = 0; i < formats.length; i++)
{
if (formats[i] instanceof DateFormat)
{
DateFormat temp = (DateFormat) formats[i];
temp.setTimeZone(timezone);
mf.setFormat(i,temp);
}
}
}
return mf.format(arguments);
}
示例2: withTimeZone
import java.util.TimeZone; //导入方法依赖的package包/类
/**
* Returns a version of this formatter customized to the provided time zone.
*/
public DateFormatter withTimeZone(TimeZone tz) {
if (!tz.equals(timeZone)) {
return new YMDDateFormatter(requestedFields, localeName, tz);
}
return this;
}
示例3: a
import java.util.TimeZone; //导入方法依赖的package包/类
public List<String> a(TimeZone timeZone, TimeZone timeZone2, List<String> list) {
if (timeZone.equals(timeZone2)) {
return list;
}
long rawOffset = (long) (((timeZone.getRawOffset() - timeZone2.getRawOffset()) / 1000) /
60);
long parseLong = Long.parseLong(((String) list.get(0)).split(":")[0]);
long parseLong2 = Long.parseLong(((String) list.get(0)).split(":")[1]);
parseLong = ((((parseLong * 60) + parseLong2) - rawOffset) + 1440) % 1440;
long parseLong3 = (((Long.parseLong(((String) list.get(1)).split(":")[1]) + (60 * Long
.parseLong(((String) list.get(1)).split(":")[0]))) - rawOffset) + 1440) % 1440;
List arrayList = new ArrayList();
List list2 = arrayList;
list2.add(String.format("%1$02d:%2$02d", new Object[]{Long.valueOf(parseLong / 60), Long
.valueOf(parseLong % 60)}));
list2 = arrayList;
list2.add(String.format("%1$02d:%2$02d", new Object[]{Long.valueOf(parseLong3 / 60), Long
.valueOf(parseLong3 % 60)}));
return arrayList;
}
示例4: printTimeZoneAvailableIDs
import java.util.TimeZone; //导入方法依赖的package包/类
public static void printTimeZoneAvailableIDs() {
String[] ids = TimeZone.getAvailableIDs();
TimeZone timeZone;
if (LOG.isDebugEnabled()) {
LOG.debug(TimeZone.getDefault().toString());
}
for (int i = 0; i < ids.length; i++) {
System.out.println("");
timeZone = TimeZone.getTimeZone(ids[i]);
if (LOG.isDebugEnabled()) {
LOG.debug("ids[" + i + "]=" + ids[i] + " timeZone=" + timeZone);
LOG.debug(timeZone.getDisplayName() + " " + timeZone.getDisplayName(true, 1, Locale.US));
}
if (timeZone.equals(TimeZone.getDefault())) {
if (LOG.isDebugEnabled()) {
LOG.debug("printTimeZoneAvailableIDs ****************************i=" + i);
}
}
}
}
示例5: withTimeZone
import java.util.TimeZone; //导入方法依赖的package包/类
@Override
public DurationFormatter withTimeZone(TimeZone tz) {
if (!tz.equals(timeZone)) {
PeriodBuilder newBuilder = builder.withTimeZone(tz);
DateFormatter newFallback = fallback == null
? null
: fallback.withTimeZone(tz);
return new BasicDurationFormatter(formatter, newBuilder,
newFallback, fallbackLimit,
localeName, tz);
}
return this;
}
示例6: setTimeZone
import java.util.TimeZone; //导入方法依赖的package包/类
/**
* Set the name of the locale that will be used when
* creating new formatters.
*
* @param timeZone The time zone to use.
* @return this BasicDurationFormatterFactory
*/
@Override
public DurationFormatterFactory setTimeZone(TimeZone timeZone) {
if (!timeZone.equals(this.timeZone)) {
this.timeZone = timeZone;
if (builder != null) {
builder = builder.withTimeZone(timeZone);
}
reset();
}
return this;
}
示例7: fetchFromPool
import java.util.TimeZone; //导入方法依赖的package包/类
private DateFormat fetchFromPool() {
final DateFormat format = pool.fetchFromPool();
final TimeZone tz = timeZone != null ? timeZone : TimeZone.getDefault();
if (!tz.equals(format.getTimeZone())) {
format.setTimeZone(tz);
}
return format;
}
示例8: main
import java.util.TimeZone; //导入方法依赖的package包/类
public static void main(String[] args) {
TimeZone defaultZone = TimeZone.getDefault();
// Make sure that TimeZone.setDefault works for trusted code
TimeZone.setDefault(NOWHERE);
if (!NOWHERE.equals(TimeZone.getDefault())) {
new RuntimeException("TimeZone.setDefault doesn't work for trusted code.");
}
// Restore defaultZone
TimeZone.setDefault(defaultZone);
if (!defaultZone.equals(TimeZone.getDefault())) {
new RuntimeException("TimeZone.setDefault doesn't restore defaultZone.");
}
// Install a SecurityManager.
System.setSecurityManager(new SecurityManager());
try {
TimeZone.setDefault(NOWHERE);
throw new RuntimeException("TimeZone.setDefault doesn't throw a SecurityException.");
} catch (SecurityException se) {
// OK
}
TimeZone tz = TimeZone.getDefault();
if (!defaultZone.equals(tz)) {
throw new RuntimeException("Default TimeZone changed: " + tz);
}
}
示例9: main
import java.util.TimeZone; //导入方法依赖的package包/类
public static void main(String[] args) {
int errors = 0;
String[] ZONES = { "GMT", "MET", "IST" };
for (String id : ZONES) {
TimeZone zone = TimeZone.getTimeZone(id);
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (ObjectOutputStream ostream = new ObjectOutputStream(baos)) {
ostream.writeObject(zone);
}
try (ObjectInputStream istream
= new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) {
if (!zone.equals(istream.readObject())) {
errors++;
System.out.println("Time zone " + id + " are not equal to serialized/deserialized one.");
} else {
System.out.println("Time zone " + id + " ok.");
}
}
} catch (IOException | ClassNotFoundException e) {
errors++;
System.out.println(e);
}
}
if (errors > 0) {
throw new RuntimeException("test failed");
}
}
示例10: subParseZoneString
import java.util.TimeZone; //导入方法依赖的package包/类
/**
* find time zone 'text' matched zoneStrings and set to internal
* calendar.
*/
private int subParseZoneString(String text, int start, CalendarBuilder calb) {
boolean useSameName = false; // true if standard and daylight time use the same abbreviation.
TimeZone currentTimeZone = getTimeZone();
// At this point, check for named time zones by looking through
// the locale data from the TimeZoneNames strings.
// Want to be able to parse both short and long forms.
int zoneIndex = formatData.getZoneIndex(currentTimeZone.getID());
TimeZone tz = null;
String[][] zoneStrings = formatData.getZoneStringsWrapper();
String[] zoneNames = null;
int nameIndex = 0;
if (zoneIndex != -1) {
zoneNames = zoneStrings[zoneIndex];
if ((nameIndex = matchZoneString(text, start, zoneNames)) > 0) {
if (nameIndex <= 2) {
// Check if the standard name (abbr) and the daylight name are the same.
useSameName = zoneNames[nameIndex].equalsIgnoreCase(zoneNames[nameIndex + 2]);
}
tz = TimeZone.getTimeZone(zoneNames[0]);
}
}
if (tz == null) {
zoneIndex = formatData.getZoneIndex(TimeZone.getDefault().getID());
if (zoneIndex != -1) {
zoneNames = zoneStrings[zoneIndex];
if ((nameIndex = matchZoneString(text, start, zoneNames)) > 0) {
if (nameIndex <= 2) {
useSameName = zoneNames[nameIndex].equalsIgnoreCase(zoneNames[nameIndex + 2]);
}
tz = TimeZone.getTimeZone(zoneNames[0]);
}
}
}
if (tz == null) {
int len = zoneStrings.length;
for (int i = 0; i < len; i++) {
zoneNames = zoneStrings[i];
if ((nameIndex = matchZoneString(text, start, zoneNames)) > 0) {
if (nameIndex <= 2) {
useSameName = zoneNames[nameIndex].equalsIgnoreCase(zoneNames[nameIndex + 2]);
}
tz = TimeZone.getTimeZone(zoneNames[0]);
break;
}
}
}
if (tz != null) { // Matched any ?
if (!tz.equals(currentTimeZone)) {
setTimeZone(tz);
}
// If the time zone matched uses the same name
// (abbreviation) for both standard and daylight time,
// let the time zone in the Calendar decide which one.
//
// Also if tz.getDSTSaving() returns 0 for DST, use tz to
// determine the local time. (6645292)
int dstAmount = (nameIndex >= 3) ? tz.getDSTSavings() : 0;
if (!(useSameName || (nameIndex >= 3 && dstAmount == 0))) {
calb.clear(Calendar.ZONE_OFFSET).set(Calendar.DST_OFFSET, dstAmount);
}
return (start + zoneNames[nameIndex].length());
}
return 0;
}
示例11: subParseZoneString
import java.util.TimeZone; //导入方法依赖的package包/类
/**
* find time zone 'text' matched zoneStrings and set to internal
* calendar.
*/
private int subParseZoneString(String text, int start, CalendarBuilder calb) {
boolean useSameName = false; // true if standard and daylight time use the same abbreviation.
TimeZone currentTimeZone = getTimeZone();
// At this point, check for named time zones by looking through
// the locale data from the TimeZoneNames strings.
// Want to be able to parse both short and long forms.
int zoneIndex = formatData.getZoneIndex(currentTimeZone.getID());
TimeZone tz = null;
String[][] zoneStrings = formatData.getZoneStringsWrapper();
String[] zoneNames = null;
int nameIndex = 0;
if (zoneIndex != -1) {
zoneNames = zoneStrings[zoneIndex];
if ((nameIndex = matchZoneString(text, start, zoneNames)) > 0) {
if (nameIndex <= 2) {
// Check if the standard name (abbr) and the daylight name are the same.
useSameName = zoneNames[nameIndex].equalsIgnoreCase(zoneNames[nameIndex + 2]);
}
tz = TimeZone.getTimeZone(zoneNames[0]);
}
}
if (tz == null) {
zoneIndex = formatData.getZoneIndex(TimeZone.getDefault().getID());
if (zoneIndex != -1) {
zoneNames = zoneStrings[zoneIndex];
if ((nameIndex = matchZoneString(text, start, zoneNames)) > 0) {
if (nameIndex <= 2) {
useSameName = zoneNames[nameIndex].equalsIgnoreCase(zoneNames[nameIndex + 2]);
}
tz = TimeZone.getTimeZone(zoneNames[0]);
}
}
}
if (tz == null) {
int len = zoneStrings.length;
for (int i = 0; i < len; i++) {
zoneNames = zoneStrings[i];
if ((nameIndex = matchZoneString(text, start, zoneNames)) > 0) {
if (nameIndex <= 2) {
useSameName = zoneNames[nameIndex].equalsIgnoreCase(zoneNames[nameIndex + 2]);
}
tz = TimeZone.getTimeZone(zoneNames[0]);
break;
}
}
}
if (tz != null) { // Matched any ?
if (!tz.equals(currentTimeZone)) {
setTimeZone(tz);
}
// If the time zone matched uses the same name
// (abbreviation) for both standard and daylight time,
// let the time zone in the Calendar decide which one.
//
// Also if tz.getDSTSaving() returns 0 for DST, use tz to
// determine the local time. (6645292)
int dstAmount = (nameIndex >= 3) ? tz.getDSTSavings() : 0;
if (!(useSameName || (nameIndex >= 3 && dstAmount == 0))) {
calb.clear(Calendar.ZONE_OFFSET).set(Calendar.DST_OFFSET, dstAmount);
}
return (start + zoneNames[nameIndex].length());
}
return -start;
}
示例12: isTimeSettingChanged
import java.util.TimeZone; //导入方法依赖的package包/类
private static boolean isTimeSettingChanged() {
TimeZone currentTZ = TimeZone.getDefault();
boolean currentDST = currentTZ.inDaylightTime(new Date());
return (!currentTZ.equals(TZ) || currentDST != DST);
}