List of usage examples for java.time ZonedDateTime from
public static ZonedDateTime from(TemporalAccessor temporal)
From source file:Main.java
public static void main(String[] args) { ZonedDateTime dateTime = ZonedDateTime.from(ZonedDateTime.now()); System.out.println(dateTime); }
From source file:Main.java
public static void main(String[] args) { ZonedDateTime dateTime = ZonedDateTime.from(ZonedDateTime.now()); String s = dateTime.format(DateTimeFormatter.ISO_DATE_TIME); System.out.println(s);// w w w . j a va 2 s . co m }
From source file:com.buffalokiwi.api.APIDate.java
/** * Attempt to take some value and turn it into a valid APIDate. * If it isn't valid, then this returns null. * // w w w . jav a 2s .c o m * @param value Jet value * @return date or null */ public static APIDate fromStringOrNull(String value) { if (value == null || value.isEmpty()) return null; for (final DateTimeFormatter fmt : FORMATS) { try { final TemporalAccessor t = fmt.parse(value); try { return new APIDate(ZonedDateTime.from(t)); } catch (DateTimeException e) { APILog.warn(LOG, e, "Failed to determine timezone. Defaulting to local offset"); final LocalDateTime local = LocalDateTime.from(t); final ZoneOffset offset = ZoneId.systemDefault().getRules().getOffset(Instant.now()); return new APIDate(ZonedDateTime.of(local, offset)); } } catch (DateTimeParseException e) { //..do nothing, yet. } } //..Not found. Log it and return null APILog.error(LOG, "Failed to parse date string:", value); return null; }
From source file:com.esri.geoportal.harvester.waf.WafFile.java
/** * Reads last modified date./*from w ww. j av a 2 s. co m*/ * @param response HTTP response * @return last modified date or <code>null</code> if unavailable */ private Date readLastModifiedDate(HttpResponse response) { try { Header lastModifedHeader = response.getFirstHeader("Last-Modified"); return lastModifedHeader != null ? Date.from(ZonedDateTime .from(DateTimeFormatter.RFC_1123_DATE_TIME.parse(lastModifedHeader.getValue())).toInstant()) : null; } catch (Exception ex) { return null; } }
From source file:msi.gama.util.GamaDate.java
public GamaDate(final IScope scope, final Temporal d) { final ZoneId zone; if (d instanceof ChronoZonedDateTime) { zone = ZonedDateTime.from(d).getZone(); } else if (d.isSupported(ChronoField.OFFSET_SECONDS)) { zone = ZoneId.ofOffset("", ZoneOffset.ofTotalSeconds(d.get(ChronoField.OFFSET_SECONDS))); } else {/* ww w . jav a2s . c o m*/ zone = GamaDateType.DEFAULT_ZONE; } if (!d.isSupported(MINUTE_OF_HOUR)) { internal = ZonedDateTime.of(LocalDate.from(d), LocalTime.of(0, 0), zone); } else if (!d.isSupported(DAY_OF_MONTH)) { internal = ZonedDateTime.of(LocalDate.from( scope == null ? Dates.DATES_STARTING_DATE.getValue() : scope.getSimulation().getStartingDate()), LocalTime.from(d), zone); } else { internal = d; } }
From source file:com.esri.geoportal.commons.gpt.client.Client.java
private Date readLastUpdated(QueryResponse.Source source) { if (source != null && source.src_lastupdate_dt != null) { try {//from w ww . java 2 s . c o m return Date.from(ZonedDateTime.from(DateTimeFormatter.ISO_DATE_TIME.parse(source.src_lastupdate_dt)) .toInstant()); } catch (Exception ex) { } } return null; }
From source file:com.esri.geoportal.harvester.ckan.CkanBroker.java
/** * Parses ISO date// w ww. ja va 2s . co m * * @param strDate ISO date as string * @return date object or <code>null</code> if unable to parse date */ private Date parseIsoDate(String strDate) { try { return Date.from(ZonedDateTime.from(DateTimeFormatter.ISO_DATE_TIME.parse(strDate)).toInstant()); } catch (Exception ex) { return null; } }
From source file:msi.gama.util.GamaDate.java
public ZonedDateTime getZonedDateTime() { return ZonedDateTime.from(internal); }
From source file:com.esri.geoportal.commons.csw.client.impl.Client.java
/** * Parses ISO date// w ww . j a v a 2 s. c o m * * @param strDate ISO date as string * @return date object or <code>null</code> if unable to parse date */ private static Date parseIsoDate(String strDate) { try { return Date.from(ZonedDateTime.from(DateTimeFormatter.ISO_DATE_TIME.parse(strDate)).toInstant()); } catch (Exception ex) { return null; } }