本文整理了Java中java.time.Clock.systemDefaultZone()
方法的一些代码示例,展示了Clock.systemDefaultZone()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Clock.systemDefaultZone()
方法的具体详情如下:
包路径:java.time.Clock
类名称:Clock
方法名:systemDefaultZone
[英]Obtains a clock that returns the current instant using the best available system clock, converting to date and time using the default time-zone.
This clock is based on the best available system clock. This may use System#currentTimeMillis(), or a higher resolution clock if one is available.
Using this method hard codes a dependency to the default time-zone into your application. It is recommended to avoid this and use a specific time-zone whenever possible. The #systemUTC() should be used when you need the current instant without the date or time.
The returned implementation is immutable, thread-safe and Serializable. It is equivalent to system(ZoneId.systemDefault()).
[中]获取一个时钟,该时钟使用最佳可用系统时钟返回当前时刻,并使用默认时区转换为日期和时间。
此时钟基于最佳可用系统时钟。这可能使用System#currentTimeMillis(),或更高分辨率的时钟(如果有)。
使用此方法将对默认时区的依赖项硬编码到应用程序中。建议避免这种情况,并尽可能使用特定的时区。当您需要当前时刻而不需要日期或时间时,应使用#systemUTC()。
返回的实现是不可变的、线程安全的和可序列化的。它相当于系统(ZoneId.systemDefault())。
代码示例来源:origin: neo4j/neo4j
public ClockContext()
{
this( Clock.systemDefaultZone() );
}
代码示例来源:origin: apache/pulsar
public Backoff(long initial, TimeUnit unitInitial, long max, TimeUnit unitMax, long mandatoryStop,
TimeUnit unitMandatoryStop) {
this(initial, unitInitial, max, unitMax, mandatoryStop, unitMandatoryStop, Clock.systemDefaultZone());
}
代码示例来源:origin: yu199195/Raincat
/**
* 获得当前的时间戳.
*
* @return 时间点
*/
public static Instant nowTimestamp() {
return Instant.now(Clock.systemDefaultZone());
}
代码示例来源:origin: confluentinc/ksql
BasicCollector(
final KsqlModuleType moduleType,
final Supplier<Boolean> activenessSupplier,
final Clock clock
) {
this.moduleType = moduleType;
this.activenessSupplier = Objects.requireNonNull(activenessSupplier, "activenessSupplier");
this.clock = Objects.requireNonNull(clock, "clock");
}
代码示例来源:origin: confluentinc/ksql
KsqlVersionCheckerAgent(
final Supplier<Boolean> activeQuerySupplier,
final boolean enableSettlingTime,
final Clock clock,
final VersionCheckerFactory versionCheckerFactory) {
this.enableSettlingTime = enableSettlingTime;
this.activeQuerySupplier = Objects.requireNonNull(activeQuerySupplier, "activeQuerySupplier");
this.clock = Objects.requireNonNull(clock, "clock");
this.versionCheckerFactory =
Objects.requireNonNull(versionCheckerFactory, "versionCheckerFactory");
}
代码示例来源:origin: yu199195/Raincat
/**
* 获得当前的日期毫秒.
*
* @return 当前毫秒数
*/
public static long nowTimeMillis() {
return Clock.systemDefaultZone().millis();
}
代码示例来源:origin: yu199195/Raincat
/**
* 获取从1970年到现在的秒数.
*
* @return 秒数
*/
public static long nowEpochSecond() {
return Clock.systemDefaultZone().instant().getEpochSecond();
}
代码示例来源:origin: apache/flume
public SyslogUtils(Integer defaultSize, Set<String> keepFields, boolean isUdp) {
this(defaultSize, keepFields, isUdp, Clock.system(Clock.systemDefaultZone().getZone()));
}
代码示例来源:origin: wildfly/wildfly
classes.add(Clock.systemDefaultZone().getClass());
classes.add(TimeZone.getDefault().getClass());
classes.add(ZoneId.systemDefault().getClass());
代码示例来源:origin: spotify/docker-client
public ContainerRegistryAuthSupplier build() {
final GoogleCredentials credentials = this.credentials.createScoped(scopes);
// log some sort of identifier for the credentials, which requires looking at the
// instance type
if (credentials instanceof ServiceAccountCredentials) {
final String clientEmail = ((ServiceAccountCredentials) credentials).getClientEmail();
log.info("loaded credentials for service account with clientEmail={}", clientEmail);
} else if (credentials instanceof UserCredentials) {
final String clientId = ((UserCredentials) credentials).getClientId();
log.info("loaded credentials for user account with clientId={}", clientId);
}
final Clock clock = Clock.systemDefaultZone();
final DefaultCredentialRefresher refresher = new DefaultCredentialRefresher();
return new ContainerRegistryAuthSupplier(credentials, clock, minimumExpiryMillis, refresher);
}
}
代码示例来源:origin: schemaspy/schemaspy
@Bean
public Clock clock() {
return Clock.systemDefaultZone();
}
代码示例来源:origin: SonarSource/sonarqube
new TempFolderProvider(),
System2.INSTANCE,
Clock.systemDefaultZone(),
代码示例来源:origin: torodb/stampede
private static StampedeConfig createStampedeConfig(Config config) {
Clock clock = Clock.systemDefaultZone();
代码示例来源:origin: SonarSource/sonarqube
private void addBootstrapComponents() {
Version apiVersion = ApiVersion.load(System2.INSTANCE);
add(
// plugins
ScannerPluginRepository.class,
PluginLoader.class,
PluginClassloaderFactory.class,
ScannerPluginJarExploder.class,
ScannerPluginPredicate.class,
ExtensionInstaller.class,
new SonarQubeVersion(apiVersion),
SonarRuntimeImpl.forSonarQube(apiVersion, SonarQubeSide.SCANNER),
StoragesManager.class,
new GlobalServerSettingsProvider(),
new GlobalConfigurationProvider(),
new ScannerWsClientProvider(),
DefaultServer.class,
new GlobalTempFolderProvider(),
DefaultHttpDownloader.class,
UriReader.class,
PluginFiles.class,
System2.INSTANCE,
Clock.systemDefaultZone(),
new MetricsRepositoryProvider(),
UuidFactoryImpl.INSTANCE);
addIfMissing(ScannerPluginInstaller.class, PluginInstaller.class);
add(CoreExtensionRepositoryImpl.class, CoreExtensionsLoader.class, ScannerCoreExtensionsInstaller.class);
addIfMissing(DefaultSettingsLoader.class, SettingsLoader.class);
addIfMissing(DefaultMetricsRepositoryLoader.class, MetricsRepositoryLoader.class);
}
代码示例来源:origin: SonarSource/sonarqube
new TempFolderProvider(),
System2.INSTANCE,
Clock.systemDefaultZone(),
代码示例来源:origin: zalando/zalenium
public ZaleniumRegistry(Hub hub) {
super(hub);
this.newSessionQueue = new NewSessionRequestQueue();
long minContainers = ZaleniumConfiguration.getDesiredContainersOnStartup();
long maxContainers = ZaleniumConfiguration.getMaxDockerSeleniumContainers();
long timeToWaitToStart = ZaleniumConfiguration.getTimeToWaitToStart();
boolean waitForAvailableNodes = ZaleniumConfiguration.isWaitForAvailableNodes();
int maxTimesToProcessRequest = ZaleniumConfiguration.getMaxTimesToProcessRequest();
int checkContainersInterval = ZaleniumConfiguration.getCheckContainersInterval();
DockeredSeleniumStarter starter = new DockeredSeleniumStarter();
AutoStartProxySet autoStart = new AutoStartProxySet(false, minContainers, maxContainers, timeToWaitToStart,
waitForAvailableNodes, starter, Clock.systemDefaultZone(), maxTimesToProcessRequest, checkContainersInterval);
proxies = autoStart;
this.matcherThread.setUncaughtExceptionHandler(new UncaughtExceptionHandler());
new TestSessionCollectorExports(proxies).register();
new ContainerStatusCollectorExports(autoStart.getStartedContainers()).register();
}
代码示例来源:origin: biezhi/learn-java8
public static void main(String[] args) {
Clock clock = Clock.systemDefaultZone();
long millis = clock.millis();
Instant instant = clock.instant();
Date legacyDate = Date.from(instant); // legacy java.util.Date
System.out.println(millis);
System.out.println(legacyDate);
}
}
代码示例来源:origin: appium/java-client
@Test(expected = TimeoutException.class)
public void testDefaultStrategy() {
final FakeElement el = new FakeElement();
final Wait<FakeElement> wait = new AppiumFluentWait<>(el, Clock.systemDefaultZone(), duration -> {
assertThat(duration.getSeconds(), is(equalTo(1L)));
Thread.sleep(duration.toMillis());
}).withPollingStrategy(AppiumFluentWait.IterationInfo::getInterval)
.withTimeout(ofSeconds(3))
.pollingEvery(ofSeconds(1));
wait.until(FakeElement::isDisplayed);
Assert.fail("TimeoutException is expected");
}
代码示例来源:origin: appium/java-client
@Test
public void testCustomStrategyOverridesDefaultInterval() {
final FakeElement el = new FakeElement();
final AtomicInteger callsCounter = new AtomicInteger(0);
final Wait<FakeElement> wait = new AppiumFluentWait<>(el, Clock.systemDefaultZone(), duration -> {
callsCounter.incrementAndGet();
assertThat(duration.getSeconds(), is(equalTo(2L)));
Thread.sleep(duration.toMillis());
}).withPollingStrategy(info -> ofSeconds(2))
.withTimeout(ofSeconds(3))
.pollingEvery(ofSeconds(1));
try {
wait.until(FakeElement::isDisplayed);
Assert.fail("TimeoutException is expected");
} catch (TimeoutException e) {
// this is expected
assertThat(callsCounter.get(), is(equalTo(2)));
}
}
代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures
@Test
public void testMetaDate() throws Exception {
Map<String, Object> param = map(
"DATE", DateValue.now(Clock.systemDefaultZone()),
"LOCAL_DATE", LocalDateTimeValue.now(Clock.systemDefaultZone()),
"TIME", TimeValue.now(Clock.systemDefaultZone()),
"LOCAL_TIME", LocalTimeValue.now(Clock.systemDefaultZone()),
"DATE_TIME", DateTimeValue.now(Clock.systemDefaultZone()),
"NULL", null);
TestUtil.testCall(db, "RETURN apoc.meta.cypher.types({param}) AS value", singletonMap("param",param), row -> {
Map<String, Object> r = (Map<String, Object>) row.get("value");
assertEquals("DATE", r.get("DATE"));
assertEquals("LOCAL_DATE_TIME", r.get("LOCAL_DATE"));
assertEquals("TIME", r.get("TIME"));
assertEquals("LOCAL_TIME", r.get("LOCAL_TIME"));
assertEquals("DATE_TIME", r.get("DATE_TIME"));
assertEquals("NULL", r.get("NULL"));
});
}
内容来源于网络,如有侵权,请联系作者删除!