Java Code Examples for java.time.Clock#tickSeconds()

The following examples show how to use java.time.Clock#tickSeconds() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TCKClock_Tick.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void test_tickSeconds_ZoneId() throws Exception {
    Clock test = Clock.tickSeconds(PARIS);
    assertEquals(test.getZone(), PARIS);
    assertEquals(test.instant().getNano(), 0);
    Thread.sleep(100);
    assertEquals(test.instant().getNano(), 0);
}
 
Example 2
Source File: TCKClock_Tick.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void test_tickSeconds_ZoneId() throws Exception {
    Clock test = Clock.tickSeconds(PARIS);
    assertEquals(test.getZone(), PARIS);
    assertEquals(test.instant().getNano(), 0);
    Thread.sleep(100);
    assertEquals(test.instant().getNano(), 0);
}
 
Example 3
Source File: TCKClock_Tick.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void test_tickSeconds_ZoneId() throws Exception {
    Clock test = Clock.tickSeconds(PARIS);
    assertEquals(test.getZone(), PARIS);
    assertEquals(test.instant().getNano(), 0);
    Thread.sleep(100);
    assertEquals(test.instant().getNano(), 0);
}
 
Example 4
Source File: TCKClock_Tick.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public void test_tickSeconds_ZoneId() throws Exception {
    Clock test = Clock.tickSeconds(PARIS);
    assertEquals(test.getZone(), PARIS);
    assertEquals(test.instant().getNano(), 0);
    Thread.sleep(100);
    assertEquals(test.instant().getNano(), 0);
}
 
Example 5
Source File: TCKClock_Tick.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public void test_tickSeconds_ZoneId() throws Exception {
    Clock test = Clock.tickSeconds(PARIS);
    assertEquals(test.getZone(), PARIS);
    assertEquals(test.instant().getNano(), 0);
    Thread.sleep(100);
    assertEquals(test.instant().getNano(), 0);
}
 
Example 6
Source File: TCKClock_Tick.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void test_tickSeconds_ZoneId() throws Exception {
    Clock test = Clock.tickSeconds(PARIS);
    assertEquals(test.getZone(), PARIS);
    assertEquals(test.instant().getNano(), 0);
    Thread.sleep(100);
    assertEquals(test.instant().getNano(), 0);
}
 
Example 7
Source File: TCKClock_Tick.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public void test_tickSeconds_ZoneId() throws Exception {
    Clock test = Clock.tickSeconds(PARIS);
    assertEquals(test.getZone(), PARIS);
    assertEquals(test.instant().getNano(), 0);
    Thread.sleep(100);
    assertEquals(test.instant().getNano(), 0);
}
 
Example 8
Source File: TCKClock_Tick.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void test_tickSeconds_ZoneId() throws Exception {
    Clock test = Clock.tickSeconds(PARIS);
    assertEquals(test.getZone(), PARIS);
    assertEquals(test.instant().getNano(), 0);
    Thread.sleep(100);
    assertEquals(test.instant().getNano(), 0);
}
 
Example 9
Source File: TCKClock_Tick.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void test_tickSeconds_ZoneId() throws Exception {
    Clock test = Clock.tickSeconds(PARIS);
    assertEquals(test.getZone(), PARIS);
    assertEquals(test.instant().getNano(), 0);
    Thread.sleep(100);
    assertEquals(test.instant().getNano(), 0);
}
 
Example 10
Source File: TCKClock_Tick.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void test_tickSeconds_ZoneId() throws Exception {
    Clock test = Clock.tickSeconds(PARIS);
    assertEquals(test.getZone(), PARIS);
    assertEquals(test.instant().getNano(), 0);
    Thread.sleep(100);
    assertEquals(test.instant().getNano(), 0);
}
 
Example 11
Source File: TCKClock_Tick.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void test_tickSeconds_ZoneId() throws Exception {
    Clock test = Clock.tickSeconds(PARIS);
    assertEquals(test.getZone(), PARIS);
    assertEquals(test.instant().getNano(), 0);
    Thread.sleep(100);
    assertEquals(test.instant().getNano(), 0);
}
 
Example 12
Source File: TCKClock_Tick.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions = NullPointerException.class)
public void test_tickSeconds_ZoneId_nullZoneId() {
    Clock.tickSeconds(null);
}
 
Example 13
Source File: JavaClockExample.java    From journaldev with MIT License 4 votes vote down vote up
public static void main(String[] args) throws InterruptedException {
	
	//1. Simple example with default system time zone
	Clock clock = Clock.systemDefaultZone();
	System.out.println(clock.getZone());

	//2. Clock instant example
	Instant instant = clock.instant();
	System.out.println(instant);
	
	//3. UTC Time zone
	clock = Clock.systemUTC();
	System.out.println(clock.getZone());

	//4. using specific time zone
	clock = Clock.system(ZoneId.of("Europe/Paris"));
	System.out.println(clock.instant());
	
	//5. Get current milliseconds
	System.out.println(clock.millis());
	System.out.println(System.currentTimeMillis());
	
	//6. Offset to future or past time
	Clock pastClock = Clock.offset(clock, Duration.ofMillis(-10000));
	System.out.println(clock.millis() - pastClock.millis());

	Clock futureClock = Clock.offset(clock, Duration.ofDays(1));
	System.out.println(futureClock.millis() - clock.millis());
	
	//7. tick example
	Clock nearestHourClock = Clock.tick(clock, Duration.ofHours(1));
	System.out.println(clock.instant());
	System.out.println(nearestHourClock.instant());
	
	Clock nearestSecondClock = Clock.tickSeconds(ZoneId.systemDefault());
	System.out.println(nearestSecondClock);
	System.out.println(nearestSecondClock.instant());
	
	//8. Fixed Clock
	Clock fixedClock = Clock.fixed(instant, ZoneId.systemDefault());
	System.out.println(fixedClock);
	System.out.println(fixedClock.instant());
	Thread.sleep(1000);
	System.out.println(fixedClock.instant());

}
 
Example 14
Source File: TCKClock_Tick.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions = NullPointerException.class)
public void test_tickSeconds_ZoneId_nullZoneId() {
    Clock.tickSeconds(null);
}
 
Example 15
Source File: TCKClock_Tick.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions = NullPointerException.class)
public void test_tickSeconds_ZoneId_nullZoneId() {
    Clock.tickSeconds(null);
}
 
Example 16
Source File: TCKClock_Tick.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions = NullPointerException.class)
public void test_tickSeconds_ZoneId_nullZoneId() {
    Clock.tickSeconds(null);
}
 
Example 17
Source File: TCKClock_Tick.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions = NullPointerException.class)
public void test_tickSeconds_ZoneId_nullZoneId() {
    Clock.tickSeconds(null);
}
 
Example 18
Source File: TCKClock_Tick.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions = NullPointerException.class)
public void test_tickSeconds_ZoneId_nullZoneId() {
    Clock.tickSeconds(null);
}
 
Example 19
Source File: Validator.java    From fernet-java8 with Apache License 2.0 2 votes vote down vote up
/**
 * Override this method if your application uses a custom clock. The default implementation returns a clock in the
 * UTC time zone with second granularity.
 *
 * @return The Clock used for all validation operations.
 */
default Clock getClock() {
    return Clock.tickSeconds(ZoneOffset.UTC);
}
 
Example 20
Source File: BoundedElasticScheduler.java    From reactor-core with Apache License 2.0 2 votes vote down vote up
/**
 * Create a {@link BoundedElasticScheduler} with the given configuration. Note that backing threads
 * (or executors) can be shared by each {@link reactor.core.scheduler.Scheduler.Worker}, so each worker
 * can contribute to the task queue size.
 *
 * @param maxThreads the maximum number of backing threads to spawn, must be strictly positive
 * @param maxTaskQueuedPerThread the maximum amount of tasks an executor can queue up
 * @param factory the {@link ThreadFactory} to name the backing threads
 * @param ttlSeconds the time-to-live (TTL) of idle threads, in seconds
 */
BoundedElasticScheduler(int maxThreads, int maxTaskQueuedPerThread, ThreadFactory factory, int ttlSeconds) {
	this(maxThreads, maxTaskQueuedPerThread, factory, ttlSeconds * 1000,
			Clock.tickSeconds(BoundedServices.ZONE_UTC));
}