List of usage examples for java.time Instant atZone
public ZonedDateTime atZone(ZoneId zone)
From source file:Main.java
public static void main(String[] args) { Instant instant = Instant.parse("2014-12-03T10:15:30.00Z"); System.out.println(instant.atZone(ZoneId.systemDefault())); }
From source file:Main.java
public static void main(String[] args) { Clock utcClock = Clock.systemUTC(); Clock defaultClock = Clock.systemDefaultZone(); Clock offsetClock = Clock.offset(Clock.systemUTC(), Duration.ofHours(-5)); ZoneId denverTimeZone = ZoneId.of("America/Denver"); ZoneId newYorkTimeZone = ZoneId.of("America/New_York"); ZoneId chicagoTimeZone = ZoneId.of("America/Chicago"); ZoneId losAngelesTimeZone = ZoneId.of("America/Los_Angeles"); Instant instant = Instant.now(defaultClock); Instant instant2 = Instant.now(utcClock); Instant instant3 = Instant.now(offsetClock); System.out.println(instant);/*from w w w.j a v a 2 s . c o m*/ System.out.println(instant2); System.out.println(instant3.plus(Duration.ofSeconds(90))); System.out.println(instant3.atZone(newYorkTimeZone)); System.out.println(instant3.atZone(chicagoTimeZone)); System.out.println(instant3.atZone(denverTimeZone)); System.out.println(instant3.atZone(losAngelesTimeZone)); }
From source file:com.rcs.shoe.shop.fx.utils.DateUtils.java
public static LocalDate convert(Date date) { Instant instant = date.toInstant(); return instant.atZone(ZoneId.systemDefault()).toLocalDate(); }
From source file:net.morimekta.idltool.IdlUtils.java
public static String formatAgo(long timestamp) { Instant instant = Instant.ofEpochSecond(timestamp / 1000); LocalDateTime local = instant.atZone(Clock.systemUTC().getZone()) .withZoneSameInstant(Clock.systemDefaultZone().getZone()).toLocalDateTime(); return DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(local).replaceAll("[T]", " "); }
From source file:com.spotify.styx.model.WorkflowConfiguration.java
public Instant addOffset(Instant next) { final String offset = offset().orElseGet(this::defaultOffset); return TimeUtil.addOffset(next.atZone(ZoneOffset.UTC), offset).toInstant(); }
From source file:edu.zipcloud.cloudstreetmarket.core.entities.Chart.java
public boolean isExpired(int ttlInMinutes) { Instant now = new Date().toInstant(); LocalDateTime localNow = now.atZone(ZoneId.systemDefault()).toLocalDateTime(); LocalDateTime localLastUpdate = DateUtils.addMinutes(lastUpdate, ttlInMinutes).toInstant() .atZone(ZoneId.systemDefault()).toLocalDateTime(); return localLastUpdate.isBefore(localNow); }
From source file:onl.area51.httpd.action.Request.java
default Request addHeader(String n, Instant i) { return addHeader(n, i.atZone(UTC)); }
From source file:com.netflix.spinnaker.echo.pipelinetriggers.health.MonitoredPollerHealth.java
private void polledRecently(Health.Builder builder) { Instant lastPollTimestamp = poller.getLastPollTimestamp(); if (lastPollTimestamp == null) { builder.unknown();/*ww w .ja v a 2 s. c o m*/ } else { val timeSinceLastPoll = Duration.between(lastPollTimestamp, now()); builder.withDetail("last.polled", formatDurationWords(timeSinceLastPoll.toMillis(), true, true) + " ago"); builder.withDetail("last.polled.at", ISO_LOCAL_DATE_TIME.format(lastPollTimestamp.atZone(ZoneId.systemDefault()))); if (timeSinceLastPoll.compareTo(Duration.of(poller.getPollingIntervalSeconds() * 2, SECONDS)) <= 0) { builder.up(); } else { builder.down(); } } }
From source file:org.nodatime.tzvalidate.Java8Dump.java
@Override public ZoneTransitions getTransitions(String id, int fromYear, int toYear) { ZoneId zone = ZoneId.of(id); ZoneRules rules = zone.getRules(); DateTimeFormatter nameFormat = DateTimeFormatter.ofPattern("zzz", Locale.US); ZoneTransitions transitions = new ZoneTransitions(id); Instant start = ZonedDateTime.of(fromYear, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC).toInstant(); transitions.addTransition(null, rules.getOffset(start).getTotalSeconds() * 1000, rules.isDaylightSavings(start), nameFormat.format(start.atZone(zone))); Instant end = ZonedDateTime.of(toYear, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC).toInstant(); ZoneOffsetTransition transition = rules.nextTransition(start.minusNanos(1)); while (transition != null && transition.getInstant().isBefore(end)) { Instant instant = transition.getInstant(); transitions.addTransition(new Date(instant.toEpochMilli()), rules.getOffset(instant).getTotalSeconds() * 1000, rules.isDaylightSavings(instant), nameFormat.format(instant.atZone(zone))); transition = rules.nextTransition(instant); }/* w ww . ja v a2 s . c o m*/ return transitions; }