Example usage for java.time ZonedDateTime now

List of usage examples for java.time ZonedDateTime now

Introduction

In this page you can find the example usage for java.time ZonedDateTime now.

Prototype

public static ZonedDateTime now(Clock clock) 

Source Link

Document

Obtains the current date-time from the specified clock.

Usage

From source file:Main.java

public static void main(String[] args) {
    ZonedDateTime z = ZonedDateTime.now(Clock.systemUTC());

    System.out.println(z);

}

From source file:Main.java

public static void main(String[] args) {
    ZonedDateTime z = ZonedDateTime.now(ZoneId.systemDefault());

    System.out.println(z);

}

From source file:Main.java

public static void main(String[] argv) {
    ZonedDateTime paris = ZonedDateTime.now(ZoneId.of("Europe/Paris"));
    ZonedDateTime london = ZonedDateTime.now(ZoneId.of("Europe/London"));
    System.out.println(paris.getHour() - london.getHour());
}

From source file:Main.java

public static void main(String[] argv) {
    ZonedDateTime here = ZonedDateTime.now(ZoneId.of("America/Los_Angeles"));
    ZonedDateTime gmtNewYear = ZonedDateTime.of(2014, 12, 31, 23, 59, 59, 0, ZoneId.of("Europe/London"));

    Duration d = Duration.between(here, gmtNewYear);
    System.out.println(d);/*from   ww  w  .ja v  a  2 s. c  om*/
}

From source file:Main.java

public static void main(String[] args) {
    ZonedDateTime nowInAthens = ZonedDateTime.now(ZoneId.of("Europe/Athens"));

    System.out.println(nowInAthens.withZoneSameInstant(ZoneId.ofOffset("UTC", ZoneOffset.ofHours(3))));
}

From source file:Main.java

public static void main(String[] args) {
    Clock clock = Clock.systemDefaultZone();

    Instant instant1 = clock.instant();
    System.out.println(instant1);

    Instant instant2 = Instant.now(clock);
    System.out.println(instant2);

    LocalDate localDate = LocalDate.now(clock);
    System.out.println(localDate);

    ZonedDateTime zoneDateTime = ZonedDateTime.now(clock);
    System.out.println(zoneDateTime);
}

From source file:Main.java

public static String getCurrentTimeStamp() {
    Clock clock = Clock.system(ZoneId.of("Europe/Berlin"));
    ZonedDateTime now = ZonedDateTime.now(clock);
    return DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(now);
}

From source file:org.pr.nb.clocks.model.NBClock.java

public NBClock(String zoneId) {
    this.zoneId = ZoneId.of(zoneId, ZoneId.SHORT_IDS);
    zoneDateTime = ZonedDateTime.now(this.zoneId);
    homeZone = StringUtils.equals(zoneId, ZoneId.systemDefault().getId());
}

From source file:com.todo.backend.security.JWTUtils.java

public static String createToken(Long userId, UserRole userRole, String secretKey) {

    final ZonedDateTime validity = ZonedDateTime.now(ZoneId.of("UTC")).plusSeconds(VALIDITY);

    return Jwts.builder().setSubject(userId.toString()).claim(AUTHORITIES_KEY, userRole.name())
            .signWith(SignatureAlgorithm.HS512, secretKey).setExpiration(Date.from(validity.toInstant()))
            .compact();// w  ww .j av  a  2s.  com
}

From source file:com.oharemza.timeteller.TimeTellerController.java

@RequestMapping(value = "/", method = RequestMethod.GET)
@ResponseBody
public String tell() {
    return DateTimeFormatter.ISO_INSTANT.format(ZonedDateTime.now(clock));
}