List of usage examples for java.time ZoneOffset from
public static ZoneOffset from(TemporalAccessor temporal)
From source file:Main.java
public static void main(String[] args) { ZoneOffset t = ZoneOffset.from(ZonedDateTime.now()); System.out.println(t); }
From source file:net.dv8tion.jda.core.EmbedBuilder.java
/** * Sets the Timestamp of the embed./*from w w w .java2 s .com*/ * * <p><b><a href="http://i.imgur.com/YP4NiER.png">Example</a></b> * * <p><b>Hint:</b> You can get the current time using {@link java.time.Instant#now() Instant.now()} or convert time from a * millisecond representation by using {@link java.time.Instant#ofEpochMilli(long) Instant.ofEpochMilli(long)}; * * @param temporal * the temporal accessor of the timestamp * * @return the builder after the timestamp has been set */ public EmbedBuilder setTimestamp(TemporalAccessor temporal) { if (temporal == null) { this.timestamp = null; } else if (temporal instanceof OffsetDateTime) { this.timestamp = (OffsetDateTime) temporal; } else { ZoneOffset offset; try { offset = ZoneOffset.from(temporal); } catch (DateTimeException ignore) { offset = ZoneOffset.UTC; } try { LocalDateTime ldt = LocalDateTime.from(temporal); this.timestamp = OffsetDateTime.of(ldt, offset); } catch (DateTimeException ignore) { try { Instant instant = Instant.from(temporal); this.timestamp = OffsetDateTime.ofInstant(instant, offset); } catch (DateTimeException ex) { throw new DateTimeException("Unable to obtain OffsetDateTime from TemporalAccessor: " + temporal + " of type " + temporal.getClass().getName(), ex); } } } return this; }