List of usage examples for java.time OffsetDateTime from
public static OffsetDateTime from(TemporalAccessor temporal)
From source file:Main.java
public static void main(String[] args) { OffsetDateTime o = OffsetDateTime.from(ZonedDateTime.now()); System.out.println(o); }
From source file:Main.java
public static void parseStr(DateTimeFormatter formatter, String text) { try {//from w w w. j a va2s . co m TemporalAccessor ta = formatter.parseBest(text, OffsetDateTime::from, LocalDateTime::from, LocalDate::from); if (ta instanceof OffsetDateTime) { OffsetDateTime odt = OffsetDateTime.from(ta); System.out.println("OffsetDateTime: " + odt); } else if (ta instanceof LocalDateTime) { LocalDateTime ldt = LocalDateTime.from(ta); System.out.println("LocalDateTime: " + ldt); } else if (ta instanceof LocalDate) { LocalDate ld = LocalDate.from(ta); System.out.println("LocalDate: " + ld); } else { System.out.println("Parsing returned: " + ta); } } catch (DateTimeParseException e) { System.out.println(e.getMessage()); } }
From source file:com.example.oauth.AccessToken.java
public AccessToken(final AccessTokenEntity accessToken) { this(accessToken.getAccessToken(), accessToken.getRefreshToken(), accessToken.getScopes(), OffsetDateTime.from(accessToken.getExpiration().toInstant().atZone(ZoneId.systemDefault()))); }
From source file:com.esri.geoportal.harvester.api.base.DataReferenceSerializer.java
/** * De-serializes data reference// w w w . j ava2 s .c o m * * @param input input stream * @return data reference * @throws IOException if de-serialization fails * @throws URISyntaxException if de-serialization fails */ public DataReference deserialize(InputStream input) throws IOException, URISyntaxException { BufferedReader reader = new BufferedReader(new InputStreamReader(input, "UTF-8")); String line = reader.readLine(); if (line != null) { String[] split = line.split(","); if (split.length == 7) { int i = 0; byte[] bBrokerUri = DECODER.decode(split[i++].getBytes("UTF-8")); byte[] bBrokerName = DECODER.decode(split[i++].getBytes("UTF-8")); byte[] bId = DECODER.decode(split[i++].getBytes("UTF-8")); byte[] bLastModifiedDate = DECODER.decode(split[i++].getBytes("UTF-8")); byte[] bSourceUri = DECODER.decode(split[i++].getBytes("UTF-8")); byte[] bContentType = DECODER.decode(split[i++].getBytes("UTF-8")); byte[] bContent = DECODER.decode(split[i++].getBytes("UTF-8")); URI brokerUri = URI.create(new String(bBrokerUri, "UTF-8")); String sBrokerName = new String(bBrokerName, "UTF-8"); String sId = new String(bId, "UTF-8"); String sLastModifiedDate = new String(bLastModifiedDate, "UTF-8"); URI sourceUri = URI.create(new String(bSourceUri, "UTF-8")); Date lastModifiedDate = !sLastModifiedDate.isEmpty() ? Date.from(OffsetDateTime.from(FORMATTER.parse(sLastModifiedDate)).toInstant()) : null; MimeType contentType = MimeType.parse(new String(bContentType, "UTF-8")); return new SimpleDataReference(brokerUri, sBrokerName, sId, lastModifiedDate, sourceUri, bContent, contentType); } } return null; }
From source file:msi.gama.util.GamaDate.java
public OffsetDateTime getOffsetDateTime() { return OffsetDateTime.from(internal); }
From source file:org.cryptomator.frontend.webdav.servlet.DavNode.java
@Override public void setProperty(DavProperty<?> property) throws DavException { final String namespacelessPropertyName = property.getName().getName(); if (Arrays.asList(DAV_CREATIONDATE_PROPNAMES).contains(namespacelessPropertyName) && property.getValue() instanceof String) { String createDateStr = (String) property.getValue(); OffsetDateTime creationDate = OffsetDateTime .from(DateTimeFormatter.RFC_1123_DATE_TIME.parse(createDateStr)); this.setCreationTime(creationDate.toInstant()); } else if (Arrays.asList(DAV_MODIFIEDDATE_PROPNAMES).contains(namespacelessPropertyName) && property.getValue() instanceof String) { String lastModifiedDateStr = (String) property.getValue(); OffsetDateTime lastModifiedDate = OffsetDateTime .from(DateTimeFormatter.RFC_1123_DATE_TIME.parse(lastModifiedDateStr)); this.setModificationTime(lastModifiedDate.toInstant()); }// w w w . j a va 2s .com properties.add(property); }
From source file:org.silverpeas.core.date.Period.java
/** * Creates a new period of time between the two specified non null date or datetime. * If date parameters are instances of {@link LocalDate}, take a look at method * {@link #between(LocalDate, LocalDate)}. * If date parameters are instances of {@link OffsetDateTime}, take a look at method * {@link #between(OffsetDateTime, OffsetDateTime)}. * @param start the start of the period. It defines the inclusive date or datetime at which the * period starts.//from w w w . j a v a 2 s.c om * @param end the end day of the period. It defines the exclusive date or the exclusive datetime * at which the period ends. The end date must be the same or after the start date. An end date * equal to the start date means the period is spanning all the day; it is equivalent to an end * date being one day after the start date. * @return the period of days between the two specified dates. * @throws IllegalArgumentException if date parameters are not both {@link LocalDate} or * {@link OffsetDateTime} instances. */ public static Period between(java.time.temporal.Temporal start, java.time.temporal.Temporal end) { if (start instanceof LocalDate && end instanceof LocalDate) { return between(LocalDate.from(start), LocalDate.from(end)); } else if (start instanceof OffsetDateTime && end instanceof OffsetDateTime) { return between(OffsetDateTime.from(start), OffsetDateTime.from(end)); } else { throw new IllegalArgumentException( "Temporal parameters must be either of type LocalDate or OffsetDateTime"); } }