Package java.time

Examples of java.time.Clock


   * @throws Exception If an unexpected error occurs.
   */
  @Test
  public void testClockFixed() throws Exception {
    // A clock which always returns a fixed date/time - in this case 'now', in UTC
    Clock clock = Clock.fixed(Instant.now(), ZoneId.of("UTC"));

    Instant instant1 = clock.instant();
    Thread.sleep(1);
    Instant instant2 = clock.instant();

    assertThat(instant2, is(instant1));
  }
View Full Code Here


   * @throws Exception If an unexpected error occurs.
   */
  @Test
  public void testClockOffset() throws Exception {
    // A clock with a date/time which is always 1 hour behind the current system date/time, in UTC
    Clock clock = Clock.offset(Clock.systemUTC(), Duration.ofHours(-1));

    Thread.sleep(1);
    long currentTimeMillis = Instant.now().toEpochMilli();
   
    // The offset clock should return a date/time, behind the current date/time
    assertThat(clock.instant().toEpochMilli(), lessThan(currentTimeMillis));
  }
View Full Code Here

TOP

Related Classes of java.time.Clock

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.