List of usage examples for java.time LocalDateTime ofInstant
public static LocalDateTime ofInstant(Instant instant, ZoneId zone)
From source file:Main.java
public static void main(String[] args) { LocalDateTime a = LocalDateTime.ofInstant(Instant.now(), ZoneOffset.UTC); System.out.println(a); }
From source file:Main.java
public static void main(String[] args) { Date date = new Date(); LocalDateTime localDateTime = LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault()); System.out.println(localDateTime); }
From source file:Main.java
public static void main(String[] args) { Instant instant = Instant.now(); LocalDateTime dateTimeFromInstant = LocalDateTime.ofInstant(instant, ZoneId.of("America/Los_Angeles")); Instant instantFromDateTime = LocalDateTime.now().toInstant(ZoneOffset.ofHours(-2)); System.out.println(dateTimeFromInstant); System.out.println(instantFromDateTime); }
From source file:Main.java
public static void main(String[] args) { // Date to Instant Instant timestamp = new Date().toInstant(); // convert Instant to LocalDateTime or other similar classes LocalDateTime date = LocalDateTime.ofInstant(timestamp, ZoneId.of(ZoneId.SHORT_IDS.get("PST"))); System.out.println("Date = " + date); }
From source file:Main.java
public static void main(String[] args) { // Instant is useful for generating a time stamp to represent machine time. Instant timestamp = Instant.now(); // Convert "machine time" to human units LocalDateTime humanTime = LocalDateTime.ofInstant(timestamp, ZoneId.systemDefault()); System.out.println(humanTime); }
From source file:Main.java
public static LocalDateTime localDateFromTimestamp(Timestamp timestamp) { return LocalDateTime.ofInstant(timestamp.toInstant(), ZoneOffset.ofHours(0)); }
From source file:Main.java
public static LocalDate fromDate(Date date) { Instant instant = Instant.ofEpochMilli(date.getTime()); return LocalDateTime.ofInstant(instant, ZoneId.systemDefault()).toLocalDate(); }
From source file:Main.java
public static LocalDateTime getDateTimeFromTimestamp(long timestamp) { if (timestamp == 0) return null; return LocalDateTime.ofInstant(Instant.ofEpochSecond(timestamp), TimeZone.getDefault().toZoneId()); }
From source file:Main.java
public static LocalDate getLocalDateFromDate(Date date) { return LocalDateTime.ofInstant(new Date(date.getTime()).toInstant(), ZoneId.systemDefault()).toLocalDate(); }
From source file:org.eclipse.smarthome.core.scheduler.CronHelper.java
/** * Returns CRON expression from the provided {@link Calendar} instance * * @param calendar the {@link Calendar} instance * @return the CRON expression// w w w .j a v a 2 s .co m * @throws NullPointerException * if {@code calendar} is null */ public static String createCronFromCalendar(Calendar calendar) { requireNonNull(calendar, "Calendar instance cannot be null"); LocalDateTime temporal = LocalDateTime.ofInstant(calendar.toInstant(), ZoneId.systemDefault()); return createCronFromTemporal(temporal); }