本文整理了Java中java.util.TimeZone.setDefault()
方法的一些代码示例,展示了TimeZone.setDefault()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TimeZone.setDefault()
方法的具体详情如下:
包路径:java.util.TimeZone
类名称:TimeZone
方法名:setDefault
[英]Sets the TimeZone
that is returned by the getDefault
method. If zone
is null, reset the default to the value it had originally when the VM first started.
[中]设置getDefault
方法返回的TimeZone
。如果zone
为空,请将默认值重置为VM首次启动时的初始值。
代码示例来源:origin: stackoverflow.com
TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
代码示例来源:origin: stackoverflow.com
TimeZone.setDefault(TimeZone.getTimeZone("Etc/UTC"));
代码示例来源:origin: stackoverflow.com
Date date1 = new Date();
System.out.println(date1);
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
// or pass in a command line arg: -Duser.timezone="UTC"
Date date2 = new Date();
System.out.println(date2);
代码示例来源:origin: jiangqqlmj/FastDev4Android
/**
* 将毫秒数转换成yyyy-MM-dd-HH-mm-ss的格式
* @param milliseconds
* @return
*/
private String paserTime(long milliseconds) {
System.setProperty("user.timezone", "Asia/Shanghai");
TimeZone tz = TimeZone.getTimeZone("Asia/Shanghai");
TimeZone.setDefault(tz);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
String times = format.format(new Date(milliseconds));
return times;
}
}
代码示例来源:origin: stackoverflow.com
UTC = TimeZone.getTimeZone("UTC");
TimeZone.setDefault(UTC);
final Calendar c = new GregorianCalendar(UTC);
c.set(1, 0, 1, 0, 0, 0);
代码示例来源:origin: hibernate/hibernate-orm
public TimeZoneConnectionProvider(String customTimeZone) {
this.customTimeZone = customTimeZone;
this.defaultTimeZone = System.setProperty( "user.timezone", customTimeZone);
TimeZone.setDefault(TimeZone.getTimeZone( customTimeZone ));
}
代码示例来源:origin: robolectric/robolectric
@Implementation
protected void setTimeZone(String timeZone) {
// Do the real check first
Shadow.directlyOn(realObject, AlarmManager.class).setTimeZone(timeZone);
// Then do the right side effect
TimeZone.setDefault(TimeZone.getTimeZone(timeZone));
}
代码示例来源:origin: hibernate/hibernate-orm
@Override
public void stop() {
super.stop();
System.setProperty( "user.timezone", defaultTimeZone);
TimeZone.setDefault(TimeZone.getTimeZone( defaultTimeZone ));
}
}
代码示例来源:origin: org.apache.commons/commons-lang3
@BeforeClass
public static void classSetUp() {
DEFAULT_LOCALE_BEFORE_TEST = Locale.getDefault();
if (!DEFAULT_LOCALE_BEFORE_TEST.equals(Locale.CANADA)) {
Locale.setDefault(Locale.CANADA);
} else {
// you seem to be from Canada...
Locale.setDefault(Locale.CHINESE);
}
TEST_DEFAULT_LOCALE = Locale.getDefault();
DEFAULT_TIMEZONE_BEFORE_TEST = TimeZone.getDefault();
final TimeZone utc = FastTimeZone.getGmtTimeZone();
if (!DEFAULT_TIMEZONE_BEFORE_TEST.equals(utc)) {
TimeZone.setDefault(utc);
} else {
TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
}
TEST_DEFAULT_TIMEZONE = TimeZone.getDefault();
}
代码示例来源:origin: querydsl/querydsl
@Before
public void setUp() {
this.timeZone = TimeZone.getDefault();
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
}
代码示例来源:origin: gocd/gocd
@Test
public void lookupCurrentDate() {
TimeZone oldDefault = TimeZone.getDefault();
TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
try {
assertThat(bvs.lookup("date"), is("1970-01-01 00:00:00 GMT"));
} finally {
TimeZone.setDefault(oldDefault);
}
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void format_date() {
TimeZone initialTz = TimeZone.getDefault();
TimeZone.setDefault(TimeZone.getTimeZone("GMT+1"));
assertThat(underTest.formatDate(Locale.ENGLISH, DateUtils.parseDateTime("2014-01-22T19:10:03+0100"))).isEqualTo("Jan 22, 2014");
TimeZone.setDefault(initialTz);
}
代码示例来源:origin: azkaban/azkaban
final String timezone = props.getString(DEFAULT_TIMEZONE_ID);
System.setProperty("user.timezone", timezone);
TimeZone.setDefault(TimeZone.getTimeZone(timezone));
DateTimeZone.setDefault(DateTimeZone.forID(timezone));
logger.info("Setting timezone to " + timezone);
代码示例来源:origin: SonarSource/sonarqube
@Test
public void format_date_time() {
TimeZone initialTz = TimeZone.getDefault();
TimeZone.setDefault(TimeZone.getTimeZone("GMT+1"));
assertThat(underTest.formatDateTime(Locale.ENGLISH, DateUtils.parseDateTime("2014-01-22T19:10:03+0100"))).startsWith("Jan 22, 2014");
TimeZone.setDefault(initialTz);
}
代码示例来源:origin: org.apache.commons/commons-lang3
date2 = dateTimeParser.parse("November 18, 2001 1:23:11.321");
defaultZone = TimeZone.getDefault();
zone = TimeZone.getTimeZone("MET");
try {
TimeZone.setDefault(zone);
dateTimeParser.setTimeZone(zone);
date3 = dateTimeParser.parse("March 30, 2003 05:30:45.000");
} finally {
dateTimeParser.setTimeZone(defaultZone);
TimeZone.setDefault(defaultZone);
cal2.setTime(date2);
try {
TimeZone.setDefault(zone);
cal3 = Calendar.getInstance();
cal3.setTime(date3);
cal8.setTime(date8);
} finally {
TimeZone.setDefault(defaultZone);
代码示例来源:origin: neo4j/neo4j
private static void checkLogRecordTimeZone( ConsistencyCheckService service, String[] args, int hoursShift, String timeZoneSuffix )
throws ToolFailureException, IOException
{
TimeZone.setDefault( TimeZone.getTimeZone( ZoneOffset.ofHours( hoursShift ) ) );
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PrintStream printStream = new PrintStream( outputStream );
runConsistencyCheckToolWith( service, printStream, args );
String logLine = readLogLine( outputStream );
assertTrue( logLine, logLine.contains( timeZoneSuffix ) );
}
代码示例来源:origin: spring-projects/spring-framework
@Test
@SuppressWarnings("deprecation")
public void testBindInstantFromJavaUtilDate() {
TimeZone defaultZone = TimeZone.getDefault();
TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
try {
MutablePropertyValues propertyValues = new MutablePropertyValues();
propertyValues.add("instant", new Date(109, 9, 31, 12, 0));
binder.bind(propertyValues);
assertEquals(0, binder.getBindingResult().getErrorCount());
assertTrue(binder.getBindingResult().getFieldValue("instant").toString().startsWith("2009-10-31"));
}
finally {
TimeZone.setDefault(defaultZone);
}
}
代码示例来源:origin: apache/kylin
@SuppressWarnings("unchecked")
@Override
public void afterPropertiesSet() throws Exception {
String timeZone = getConfig().getTimeZone();
TimeZone tzone = TimeZone.getTimeZone(timeZone);
TimeZone.setDefault(tzone);
final KylinConfig kylinConfig = KylinConfig.getInstanceFromEnv();
final Scheduler<AbstractExecutable> scheduler = (Scheduler<AbstractExecutable>) SchedulerFactory
.scheduler(kylinConfig.getSchedulerType());
scheduler.init(new JobEngineConfig(kylinConfig), new ZookeeperJobLock());
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
try {
scheduler.shutdown();
} catch (SchedulerException e) {
logger.error("error occurred to shutdown scheduler", e);
}
}
}));
}
代码示例来源:origin: robolectric/robolectric
@Before
public void setUp() {
context = ApplicationProvider.getApplicationContext();
alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
shadowAlarmManager = shadowOf(alarmManager);
activity = Robolectric.setupActivity(Activity.class);
TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
assertThat(TimeZone.getDefault().getID()).isEqualTo("America/Los_Angeles");
}
代码示例来源:origin: commons-collections/commons-collections
public void testInstantiateFactoryComplex() {
TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
// 2nd Jan 1970
Factory factory = FactoryUtils.instantiateFactory(Date.class,
new Class[] {Integer.TYPE, Integer.TYPE, Integer.TYPE},
new Object[] {new Integer(70), new Integer(0), new Integer(2)});
assertNotNull(factory);
Object created = factory.create();
assertTrue(created instanceof Date);
// long time of 1 day (== 2nd Jan 1970)
assertEquals(new Date(1000 * 60 * 60 * 24), created);
}
内容来源于网络,如有侵权,请联系作者删除!