List of usage examples for java.time LocalDateTime now
public static LocalDateTime now()
From source file:Main.java
public static void main(String[] args) { LocalDateTime a = LocalDateTime.of(2014, 6, 30, 12, 00); LocalDateTime b = LocalDateTime.now(); Temporal t = a.adjustInto(b); System.out.println(t);/*from www . jav a2 s . c o m*/ }
From source file:Main.java
public static void main(String[] args) { LocalDateTime a = LocalDateTime.of(2014, 6, 30, 12, 00); long l = a.until(LocalDateTime.now(), ChronoUnit.DAYS); System.out.println(l);//w w w. ja v a 2 s .co m }
From source file:Main.java
public static void main(String[] args) { String DATE_FORMAT = "dd/MM/yyyy HH:mm:ss"; LocalDateTime ldt = LocalDateTime.now(); DateTimeFormatter dtf = DateTimeFormatter.ofPattern(DATE_FORMAT); System.out.println(ldt.format(dtf)); }
From source file:Main.java
public static void main(String[] args) { ZonedDateTime z = ZonedDateTime.ofLocal(LocalDateTime.now(), ZoneId.systemDefault(), ZoneOffset.UTC); System.out.println(z);//from w w w . ja v a2 s . co m }
From source file:Main.java
public static void main(String[] args) { ZonedDateTime z = ZonedDateTime.ofStrict(LocalDateTime.now(), ZoneOffset.UTC, ZoneId.systemDefault()); System.out.println(z);/*w w w .j ava2s . c o m*/ }
From source file:Main.java
public static void main(String[] args) { ZonedDateTime z = ZonedDateTime.ofInstant(LocalDateTime.now(), ZoneOffset.UTC, ZoneId.systemDefault()); System.out.println(z);/*from w ww .j ava 2 s. c om*/ }
From source file:Main.java
public static void main(String[] args) { // current /*from ww w. ja v a 2 s. c om*/ LocalDateTime localDateTime1 = LocalDateTime.now(); System.out.println(localDateTime1); // 2014-06-21T16:12:34 LocalDateTime localDateTime2 = LocalDateTime.of(2014, Month.JUNE, 21, 16, 12, 34); System.out.println(localDateTime2); // from a local date and a local time LocalDate localDate1 = LocalDate.of(2014, 5, 10); LocalTime localTime = LocalTime.of(16, 18, 41); LocalDateTime localDateTime3 = LocalDateTime.of(localDate1, localTime); System.out.println(localDateTime3); }
From source file:Main.java
public static void main(String[] args) { System.out.println(formatDateTime(LocalDateTime.now())); System.out.println(parse("2000-02-01 12:23:34")); }
From source file:Main.java
public static void main(String[] args) { LocalDate tomorrow = LocalDate.now().plusDays(1); // before 5 hours and 30 minutes LocalDateTime dateTime = LocalDateTime.now().minusHours(5).minusMinutes(30); System.out.println("additionSubtraction: tomorrow: " + tomorrow); System.out.println("additionSubtraction: dateTime: " + dateTime); }
From source file:Main.java
public static void main(String[] argv) { LocalDateTime now = LocalDateTime.now(); ZonedDateTime zonedDateTime = ZonedDateTime.of(now, TimeZone.NEW_YORK); System.out.println("now = " + now); System.out.println("Current date and time in a particular timezone : " + zonedDateTime); now = LocalDateTime.now(TimeZone.INDIA); System.out.println("now in India = " + now); zonedDateTime = ZonedDateTime.now(); System.out.println("zonedDateTime with default(system) timezone = " + zonedDateTime); System.out.println("zonedDateTime with India timezone = " + ZonedDateTime.now(TimeZone.INDIA)); String isoFormatted = DateTimeFormatter.ISO_INSTANT.format(ZonedDateTime.now(TimeZone.INDIA)); System.out.println("ISO Formatted = " + isoFormatted); ZonedDateTime utahMarch8thAt2AM = ZonedDateTime.of(LocalDateTime.of(2015, 3, 8, 1, 0), TimeZone.UTAH); System.out.println("utahMarch8thAt2AM = " + utahMarch8thAt2AM); System.out.println("utahMarch8thAt2AM.plusHours(1) = " + utahMarch8thAt2AM.plusHours(1)); System.out.println("utahMarch8thAt2AM.plusHours(2) = " + utahMarch8thAt2AM.plusHours(2)); }