List of usage examples for java.time ZonedDateTime ofInstant
public static ZonedDateTime ofInstant(Instant instant, ZoneId zone)
From source file:Main.java
public static void main(String[] args) { ZonedDateTime z = ZonedDateTime.ofInstant(Instant.now(), ZoneId.systemDefault()); System.out.println(z);/*from w ww. j av a 2 s . c om*/ }
From source file:Main.java
public static void main(String[] args) { Clock defaultClock = Clock.systemDefaultZone(); Instant instant = Instant.now(defaultClock); ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(instant, ZoneId.systemDefault()); System.out.println(zonedDateTime); }
From source file:Main.java
public static ZonedDateTime toZonedDateTime(Date utilDate) { if (utilDate == null) { return null; }/*from w w w. java 2 s .com*/ final ZoneId systemDefault = ZoneId.systemDefault(); return ZonedDateTime.ofInstant(utilDate.toInstant(), systemDefault); }
From source file:Main.java
public static ZonedDateTime getDateTime(Timestamp timestamp) { return timestamp != null ? ZonedDateTime.ofInstant(Instant.ofEpochMilli(timestamp.getTime()), ZoneOffset.UTC) : null;//from w w w.j ava 2s . com }
From source file:org.openhab.binding.gardena.internal.util.DateUtils.java
/** * Converts a string to a Date, trying different date formats used by Gardena. *//* w ww. j a va 2s .co m*/ public static Date parseToDate(String text) { if (StringUtils.isNotBlank(text)) { Date parsedDate = null; for (String dateFormat : dateFormats) { try { parsedDate = new SimpleDateFormat(dateFormat).parse(text); ZonedDateTime gmt = ZonedDateTime.ofInstant(parsedDate.toInstant(), ZoneOffset.UTC); LocalDateTime here = gmt.withZoneSameInstant(ZoneId.systemDefault()).toLocalDateTime(); parsedDate = Date.from(here.toInstant(ZoneOffset.UTC)); break; } catch (ParseException ex) { } } if (parsedDate == null) { LOGGER.error("Can't parse date {}", text); } return parsedDate; } else { return null; } }
From source file:org.eclipse.smarthome.binding.weatherunderground.internal.json.WeatherUndergroundJsonUtils.java
/** * Convert a string representing an Epoch value into a Calendar object * * @param value the Epoch value as a string * * @return the ZonedDateTime object representing the date and time of the Epoch * or null in case of conversion error */// ww w . ja v a2s. c o m public static ZonedDateTime convertToZonedDateTime(String value) { if (isValid(value)) { try { Instant epochSeconds = Instant.ofEpochSecond(Long.valueOf(value)); return ZonedDateTime.ofInstant(epochSeconds, TimeZone.getDefault().toZoneId()); } catch (DateTimeException e) { LoggerFactory.getLogger(WeatherUndergroundJsonUtils.class) .debug("Cannot convert {} to ZonedDateTime", value); } } return null; }
From source file:ch.digitalfondue.npjt.mapper.ZonedDateTimeMapper.java
private static Object toZonedDateTime(Timestamp timestamp) { if (timestamp == null) { return null; }/*from w w w .ja v a2 s. c om*/ return ZonedDateTime.ofInstant(timestamp.toInstant(), UTC_Z_ID); }
From source file:com.inversoft.json.ZonedDateTimeDeserializer.java
@Override public ZonedDateTime deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { JsonToken t = jp.getCurrentToken();//from w w w .ja v a 2s .co m long value; if (t == JsonToken.VALUE_NUMBER_INT || t == JsonToken.VALUE_NUMBER_FLOAT) { value = jp.getLongValue(); } else if (t == JsonToken.VALUE_STRING) { String str = jp.getText().trim(); if (str.length() == 0) { return null; } try { value = Long.parseLong(str); } catch (NumberFormatException e) { throw ctxt.mappingException(handledType()); } } else { throw ctxt.mappingException(handledType()); } return ZonedDateTime.ofInstant(Instant.ofEpochMilli(value), ZoneOffset.UTC); }
From source file:org.primeframework.mvc.parameter.convert.converters.ZonedDateTimeConverter.java
protected Object stringToObject(String value, Type convertTo, Map<String, String> attributes, String expression) throws ConversionException, ConverterStateException { if (emptyIsNull && StringUtils.isBlank(value)) { return null; }//w ww . j a v a 2s . c o m String format = attributes.get("dateTimeFormat"); if (format == null) { // Try checking if this is an instant try { long instant = Long.parseLong(value); return ZonedDateTime.ofInstant(Instant.ofEpochMilli(instant), ZoneOffset.UTC); } catch (NumberFormatException e) { throw new ConverterStateException("You must provide the dateTimeFormat dynamic attribute for " + "the form fields [" + expression + "] that maps to DateTime properties in the action. " + "If you are using a text field it will look like this: [@jc.text _dateTimeFormat=\"MM/dd/yyyy hh:mm:ss aa Z\"]\n\n" + "NOTE: The format must include the time and a timezone. Otherwise, it will be unparseable"); } } return toDateTime(value, format); }
From source file:org.lizardirc.beancounter.commands.earthquake.GeoJsonFeatureProperty.java
public ZonedDateTime getEventTime() { return ZonedDateTime.ofInstant(Instant.ofEpochMilli(eventTime), ZoneId.systemDefault()); }