本文整理汇总了Java中java.util.TimeZone.getTimeZone方法的典型用法代码示例。如果您正苦于以下问题:Java TimeZone.getTimeZone方法的具体用法?Java TimeZone.getTimeZone怎么用?Java TimeZone.getTimeZone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.TimeZone
的用法示例。
在下文中一共展示了TimeZone.getTimeZone方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: filenameMinute
import java.util.TimeZone; //导入方法依赖的package包/类
@Test
public void filenameMinute() throws Exception {
final TimeZone tz = TimeZone.getTimeZone("UTC");
final String base = "mins";
// Current rolled file for the current minute
final Path expected = testDir.resolve(base + currentMinExt(tz));
// Set the RollingFileWriter to roll every minute
final RollingFileWriter w = new RollingFileWriter(testDir, base, tz, true);
w.write("mo data mo problems", 0, 0);
w.close();
// Just in case minute rolled during test, check before and after minutes
Path p = w.getCurrentFile();
assertTrue(p.equals(expected) ||
p.equals(testDir.resolve(base + currentMinExt(tz))));
}
示例2: Test4031502
import java.util.TimeZone; //导入方法依赖的package包/类
public void Test4031502() {
// This bug actually occurs on Windows NT as well, and doesn't
// require the host zone to be set; it can be set in Java.
String[] ids = TimeZone.getAvailableIDs();
boolean bad = false;
for (int i = 0; i < ids.length; ++i) {
TimeZone zone = TimeZone.getTimeZone(ids[i]);
GregorianCalendar cal = new GregorianCalendar(zone);
cal.clear();
cal.set(1900, 15, 5, 5, 8, 13);
if (cal.get(HOUR) != 5) {
logln(zone.getID() + " "
+ //zone.useDaylightTime() + " "
+ cal.get(DST_OFFSET) / (60 * 60 * 1000) + " "
+ zone.getRawOffset() / (60 * 60 * 1000)
+ ": HOUR = " + cal.get(HOUR));
bad = true;
}
}
if (bad) {
errln("TimeZone problems with GC");
}
}
示例3: testHourOfDay
import java.util.TimeZone; //导入方法依赖的package包/类
@Test
public void testHourOfDay() {
TimeZone gmt = TimeZone.getTimeZone("Universal");
Calendar test = Calendar.getInstance(gmt);
test.set(Calendar.YEAR, 1969);
test.set(Calendar.MONTH, Calendar.JULY);
test.set(Calendar.DATE, 20);
test.set(Calendar.HOUR_OF_DAY, 3);
assertEquals(1969, test.get(Calendar.YEAR));
assertEquals(Calendar.JULY, test.get(Calendar.MONTH));
assertEquals(20, test.get(Calendar.DATE));
assertEquals(3, test.get(Calendar.HOUR));
assertEquals(Calendar.AM, test.get(Calendar.AM_PM));
assertEquals(3, test.get(Calendar.HOUR_OF_DAY));
}
示例4: setDateVariables
import java.util.TimeZone; //导入方法依赖的package包/类
protected void setDateVariables(boolean fromConstructor) {
boolean alreadySet = ssiExternalResolver.getVariableValue(className
+ ".alreadyset") != null;
//skip this if we are being called from the constructor, and this has
// already
// been set
if (!(fromConstructor && alreadySet)) {
ssiExternalResolver.setVariableValue(className + ".alreadyset",
"true");
Date date = new Date();
TimeZone timeZone = TimeZone.getTimeZone("GMT");
String retVal = formatDate(date, timeZone);
//If we are setting on of the date variables, we want to remove
// them from the
// user
//defined list of variables, because this is what Apache does
setVariableValue("DATE_GMT", null);
ssiExternalResolver.setVariableValue(className + ".DATE_GMT",
retVal);
retVal = formatDate(date, null);
setVariableValue("DATE_LOCAL", null);
ssiExternalResolver.setVariableValue(className + ".DATE_LOCAL",
retVal);
retVal = formatDate(new Date(lastModifiedDate), null);
setVariableValue("LAST_MODIFIED", null);
ssiExternalResolver.setVariableValue(className + ".LAST_MODIFIED",
retVal);
}
}
示例5: testDateConstructor1
import java.util.TimeZone; //导入方法依赖的package包/类
/**
* In GMT, the end of 29 Feb 2004 is java.util.Date(1,078,099,199,999L).
* Use this to check the day constructor.
*/
public void testDateConstructor1() {
TimeZone zone = TimeZone.getTimeZone("GMT");
Day d1 = new Day(new Date(1078099199999L), zone);
Day d2 = new Day(new Date(1078099200000L), zone);
assertEquals(MonthConstants.FEBRUARY, d1.getMonth());
assertEquals(1078099199999L, d1.getLastMillisecond(zone));
assertEquals(MonthConstants.MARCH, d2.getMonth());
assertEquals(1078099200000L, d2.getFirstMillisecond(zone));
}
示例6: testDateConstructor2
import java.util.TimeZone; //导入方法依赖的package包/类
/**
* In Helsinki, the end of 29 Feb 2004 is java.util.Date(1,078,091,999,999L). Use this to
* check the Day constructor.
*/
public void testDateConstructor2() {
final TimeZone zone = TimeZone.getTimeZone("Europe/Helsinki");
final Day d1 = new Day(new Date(1078091999999L), zone);
final Day d2 = new Day(new Date(1078092000000L), zone);
assertEquals(SerialDate.FEBRUARY, d1.getMonth());
assertEquals(1078091999999L, d1.getLastMillisecond(zone));
assertEquals(SerialDate.MARCH, d2.getMonth());
assertEquals(1078092000000L, d2.getFirstMillisecond(zone));
}
示例7: testDateConstructor1
import java.util.TimeZone; //导入方法依赖的package包/类
/**
* In GMT, the end of Feb 2000 is java.util.Date(951,868,799,999L). Use this to check the
* Month constructor.
*/
public void testDateConstructor1() {
final TimeZone zone = TimeZone.getTimeZone("GMT");
final Month m1 = new Month(new Date(951868799999L), zone);
final Month m2 = new Month(new Date(951868800000L), zone);
assertEquals(Month.FEBRUARY, m1.getMonth());
assertEquals(951868799999L, m1.getLastMillisecond(zone));
assertEquals(Month.MARCH, m2.getMonth());
assertEquals(951868800000L, m2.getFirstMillisecond(zone));
}
示例8: Test4149677
import java.util.TimeZone; //导入方法依赖的package包/类
/**
* Reported bug is that a GregorianCalendar with a cutover of Date(Long.MAX_VALUE)
* doesn't behave as a pure Julian calendar.
* CANNOT REPRODUCE THIS BUG
*/
public void Test4149677() {
TimeZone[] zones = {TimeZone.getTimeZone("GMT"),
TimeZone.getTimeZone("PST"),
TimeZone.getTimeZone("EAT")};
for (int i = 0; i < zones.length; ++i) {
GregorianCalendar calendar = new GregorianCalendar(zones[i]);
// Make sure extreme values don't wrap around
calendar.setTime(new Date(Long.MIN_VALUE));
if (calendar.get(ERA) != GregorianCalendar.BC) {
errln("Fail: Date(Long.MIN_VALUE) has an AD year in " + zones[i]);
}
calendar.setTime(new Date(Long.MAX_VALUE));
if (calendar.get(ERA) != GregorianCalendar.AD) {
errln("Fail: Date(Long.MAX_VALUE) has a BC year in " + zones[i]);
}
calendar.setGregorianChange(new Date(Long.MAX_VALUE));
// to obtain a pure Julian calendar
boolean is100Leap = calendar.isLeapYear(100);
if (!is100Leap) {
errln("test failed with zone " + zones[i].getID());
errln(" cutover date is Date(Long.MAX_VALUE)");
errln(" isLeapYear(100) returns: " + is100Leap);
}
}
}
示例9: configureTimezone
import java.util.TimeZone; //导入方法依赖的package包/类
/**
* Configures the client's timezone if required.
*
* @throws SQLException
* if the timezone the server is configured to use can't be
* mapped to a Java timezone.
*/
private void configureTimezone() throws SQLException {
String configuredTimeZoneOnServer = this.serverVariables.get("timezone");
if (configuredTimeZoneOnServer == null) {
configuredTimeZoneOnServer = this.serverVariables.get("time_zone");
if ("SYSTEM".equalsIgnoreCase(configuredTimeZoneOnServer)) {
configuredTimeZoneOnServer = this.serverVariables.get("system_time_zone");
}
}
String canonicalTimezone = getServerTimezone();
if ((getUseTimezone() || !getUseLegacyDatetimeCode()) && configuredTimeZoneOnServer != null) {
// user can override this with driver properties, so don't detect if that's the case
if (canonicalTimezone == null || StringUtils.isEmptyOrWhitespaceOnly(canonicalTimezone)) {
try {
canonicalTimezone = TimeUtil.getCanonicalTimezone(configuredTimeZoneOnServer, getExceptionInterceptor());
} catch (IllegalArgumentException iae) {
throw SQLError.createSQLException(iae.getMessage(), SQLError.SQL_STATE_GENERAL_ERROR, getExceptionInterceptor());
}
}
}
if (canonicalTimezone != null && canonicalTimezone.length() > 0) {
this.serverTimezoneTZ = TimeZone.getTimeZone(canonicalTimezone);
//
// The Calendar class has the behavior of mapping unknown timezones to 'GMT' instead of throwing an exception, so we must check for this...
//
if (!canonicalTimezone.equalsIgnoreCase("GMT") && this.serverTimezoneTZ.getID().equals("GMT")) {
throw SQLError.createSQLException("No timezone mapping entry for '" + canonicalTimezone + "'", SQLError.SQL_STATE_ILLEGAL_ARGUMENT,
getExceptionInterceptor());
}
this.isServerTzUTC = !this.serverTimezoneTZ.useDaylightTime() && this.serverTimezoneTZ.getRawOffset() == 0;
}
}
示例10: getUTCTime
import java.util.TimeZone; //导入方法依赖的package包/类
public String getUTCTime() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-d'T'HH:mm:ss'Z'");
sdf.setTimeZone(new SimpleTimeZone(SimpleTimeZone.UTC_TIME, "UTC"));
Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
String utcTime = sdf.format(cal.getTime());
this.utcTime = utcTime;
return utcTime;
}
示例11: getCurrentTime
import java.util.TimeZone; //导入方法依赖的package包/类
protected String getCurrentTime() {
TimeZone tz = TimeZone.getTimeZone("UTC");
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
df.setTimeZone(tz);
String nowAsISO = df.format(new Date());
return nowAsISO;
}
示例12: compare
import java.util.TimeZone; //导入方法依赖的package包/类
@Override
public int compare(TimezoneDTO o1, TimezoneDTO o2) {
if (o1 != null && o2 != null && o1.getTimeZoneId() != null && o2.getTimeZoneId() != null) {
TimeZone o1TimeZone = TimeZone.getTimeZone(o1.getTimeZoneId());
TimeZone o2TimeZone = TimeZone.getTimeZone(o2.getTimeZoneId());
int rawOffsetDifference = o1TimeZone.getRawOffset() - o2TimeZone.getRawOffset();
int compareResult = (rawOffsetDifference != 0) ? rawOffsetDifference
: o1TimeZone.getID().compareTo(o2TimeZone.getID());
return compareResult;
} else if (o1 != null) {
return 1;
} else {
return -1;
}
}
示例13: getBeijingNowTime
import java.util.TimeZone; //导入方法依赖的package包/类
/**
* 获取北京时间
*/
public static String getBeijingNowTime(String format) {
TimeZone timezone = TimeZone.getTimeZone("Asia/Shanghai");
Date date = new Date(currentTimeMillis());
SimpleDateFormat formatter = new SimpleDateFormat(format, Locale.getDefault());
formatter.setTimeZone(timezone);
return formatter.format(date);
}
示例14: putTime
import java.util.TimeZone; //导入方法依赖的package包/类
/**
* Private helper routine for marshalling a DER UTC/Generalized
* time/date value. If the tag specified is not that for UTC Time
* then it defaults to Generalized Time.
* @param d the date to be marshalled
* @param tag the tag for UTC Time or Generalized Time
*/
private void putTime(Date d, byte tag) throws IOException {
/*
* Format the date.
*/
TimeZone tz = TimeZone.getTimeZone("GMT");
String pattern = null;
if (tag == DerValue.tag_UtcTime) {
pattern = "yyMMddHHmmss'Z'";
} else {
tag = DerValue.tag_GeneralizedTime;
pattern = "yyyyMMddHHmmss'Z'";
}
SimpleDateFormat sdf = new SimpleDateFormat(pattern, Locale.US);
sdf.setTimeZone(tz);
byte[] time = (sdf.format(d)).getBytes("ISO-8859-1");
/*
* Write the formatted date.
*/
write(tag);
putLength(time.length);
write(time);
}
示例15: setUp
import java.util.TimeZone; //导入方法依赖的package包/类
protected void setUp() throws Exception {
JSON.defaultTimeZone = TimeZone.getTimeZone("Asia/Shanghai");
JSON.defaultLocale = Locale.CHINA;
}