List of usage examples for java.time LocalDateTime from
public static LocalDateTime from(TemporalAccessor temporal)
From source file:net.dv8tion.jda.core.EmbedBuilder.java
/** * Sets the Timestamp of the embed.//from w w w. j a va 2 s . c om * * <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; }
From source file:msi.gama.util.GamaDate.java
public IList<?> listValue(final IScope scope, final IType<?> ct) { final LocalDateTime ld = LocalDateTime.from(internal); return GamaListFactory.create(scope, ct, ld.getYear(), ld.getMonthValue(), ld.getDayOfWeek().getValue(), ld.getHour(), ld.getMinute(), ld.getSecond()); }
From source file:msi.gama.util.GamaDate.java
public LocalDateTime getLocalDateTime() { return LocalDateTime.from(internal); }
From source file:org.talend.dataprep.transformation.actions.date.ComputeTimeSinceTest.java
/** * Compute time since ./*w w w .j a v a 2 s .c o m*/ * * @param date the date to compute from. * @param pattern the pattern to use. * @param unit the unit for the result. * @param sinceWhen the date to calculate since when * @return time since now in the wanted unit. */ String computeTimeSince(String date, String pattern, ChronoUnit unit, String sinceWhen) { DateTimeFormatter format = DateTimeFormatter.ofPattern(pattern); Temporal since; if (sinceWhen == null) { since = LocalDateTime.now(); } else { since = LocalDateTime.parse(sinceWhen, format); } LocalDateTime start; try { start = LocalDateTime.parse(date, format); } catch (Exception e) { start = null; } if (start == null) { LocalDate temp = LocalDate.parse(date, format); start = temp.atStartOfDay(); } Temporal result = LocalDateTime.from(start); return String.valueOf(unit.between(result, since)); }