List of usage examples for java.time Instant now
public static Instant now()
From source file:Main.java
public static void main(String[] args) { Instant instant = Instant.parse("2014-12-03T10:15:30.00Z"); System.out.println(instant.compareTo(Instant.now())); }
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) { Instant instant = Instant.parse("2014-12-03T10:15:30.00Z"); Temporal t = instant.adjustInto(Instant.now()); System.out.println(t);/*from w w w.j a v a 2s . co m*/ }
From source file:Main.java
public static void main(String[] args) { Duration d1 = Duration.ofSeconds(55); Duration d2 = Duration.ofSeconds(-17); Instant i1 = Instant.now(); Instant i4 = i1.plus(d1);//ww w . j av a 2s. c om Instant i5 = i1.minus(d2); Duration d3 = d1.plus(d2); System.out.println(d3); }
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(); // How many seconds have occurred since the beginning of the Java epoch. long secondsFromEpoch = Instant.ofEpochSecond(0L).until(Instant.now(), ChronoUnit.SECONDS); System.out.println(secondsFromEpoch); }
From source file:Main.java
public static void main(String[] argv) { Date dateFromInstant = Date.from(Instant.now()); System.out.println(dateFromInstant); java.util.TimeZone timeZone = java.util.TimeZone.getTimeZone(ZoneId.of("America/Los_Angeles")); System.out.println(timeZone); GregorianCalendar gregorianCalendar = GregorianCalendar.from(ZonedDateTime.now()); }
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 void main(String[] args) { TemporalAdjuster temporalAdjuster = (Temporal t) -> t.plus(Period.ofDays(10)); System.out.println(temporalAdjuster); TemporalAdjuster fourMinutesFromNow = temporal -> temporal.plus(4, ChronoUnit.MINUTES); LocalTime localTime1 = LocalTime.of(12, 0, 0); System.out.println(localTime1.with(temporal -> temporal.plus(4, ChronoUnit.MINUTES))); System.out.println(Instant.now().with(temporalAdjuster)); LocalDate localDate1 = LocalDate.of(2013, 12, 13); System.out.println(localDate1.with(TemporalAdjusters.lastDayOfMonth())); }
From source file:Main.java
public static void main(String[] args) { LocalDate date = LocalDate.now(); // default format System.out.println("Default format of LocalDate=" + date); // specific format System.out.println(date.format(DateTimeFormatter.ofPattern("d::MMM::uuuu"))); System.out.println(date.format(DateTimeFormatter.BASIC_ISO_DATE)); LocalDateTime dateTime = LocalDateTime.now(); // default format System.out.println("Default format of LocalDateTime=" + dateTime); // specific format System.out.println(dateTime.format(DateTimeFormatter.ofPattern("d::MMM::uuuu HH::mm::ss"))); System.out.println(dateTime.format(DateTimeFormatter.BASIC_ISO_DATE)); Instant timestamp = Instant.now(); // default format System.out.println("Default format of Instant=" + timestamp); // Parse examples LocalDateTime dt = LocalDateTime.parse("27::Apr::2014 21::39::48", DateTimeFormatter.ofPattern("d::MMM::uuuu HH::mm::ss")); System.out.println("Default format after parsing = " + dt); }
From source file:Main.java
public static void main(String[] args) { Path path = Paths.get("C:\\Java_Dev\\test1.txt"); try {//ww w . j a va2 s .co m BasicFileAttributeView bfv = Files.getFileAttributeView(path, BasicFileAttributeView.class); BasicFileAttributes bfa = bfv.readAttributes(); System.out.format("Size:%s bytes %n", bfa.size()); System.out.format("Creation Time:%s %n", bfa.creationTime()); System.out.format("Last Access Time:%s %n", bfa.lastAccessTime()); FileTime newLastModifiedTime = null; FileTime newLastAccessTime = null; FileTime newCreateTime = FileTime.from(Instant.now()); bfv.setTimes(newLastModifiedTime, newLastAccessTime, newCreateTime); } catch (IOException e) { e.printStackTrace(); } }