List of usage examples for java.time LocalDateTime now
public static LocalDateTime now()
From source file:Main.java
public static void main(String[] args) { DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'"); LocalDateTime now = LocalDateTime.now(); LocalDateTime then = now.minusDays(7); System.out.println(String.format("Now: %s\nThen: %s", now.format(format), then.format(format))); }
From source file:Main.java
public static void main(String[] args) { Duration duration = Duration.ofDays(2); Temporal l = duration.addTo(LocalDateTime.now()); System.out.println(l);/* w w w. j av a 2s .c o m*/ }
From source file:Main.java
public static void main(String[] args) { Duration duration = Duration.ofDays(2); Temporal l = duration.subtractFrom(LocalDateTime.now()); System.out.println(l);// w w w .j a v a2 s.c o m }
From source file:Main.java
public static void main(String[] argv) { ZoneId INDIA = ZoneId.of("Asia/Kolkata"); LocalDateTime utah = LocalDateTime.now(); LocalDateTime india = LocalDateTime.now(INDIA); long betweenHours = ChronoUnit.HOURS.between(utah, india); long betweenMins = ChronoUnit.MINUTES.between(utah, india); System.out.println("betweenHours = " + betweenHours); System.out.println("betweenMins = " + (betweenMins / 60.0)); }
From source file:Main.java
public static void main(String[] argv) { ZoneId INDIA = ZoneId.of("Asia/Kolkata"); LocalDateTime datetime = LocalDateTime.now(); ZoneOffset offset = ZoneOffset.of("+05:30"); OffsetDateTime date = OffsetDateTime.of(datetime, offset); System.out.println("OffsetDateTime.now() = " + OffsetDateTime.now()); System.out.println("OffsetDateTime.now(TimeZone.INDIA) = " + OffsetDateTime.now(INDIA)); System.out.println("Date and Time: " + datetime); System.out.println("Date and Time with timezone offset: " + date); }
From source file:Main.java
public static void main(String[] argv) { LocalDate today = LocalDate.now(); LocalTime time = LocalTime.now(); LocalDateTime timeWithDate = LocalDateTime.now(); System.out.println("today = " + today); System.out.println("local date with time now = " + timeWithDate); System.out.println("time = " + time); }
From source file:Main.java
public static void main(String[] args) { LocalDateTime now = LocalDateTime.now(); ZoneId usChicago = ZoneId.of("America/Chicago"); System.out.println("Zone ID: " + usChicago.getId()); ZoneRules rules = usChicago.getRules(); System.out.println("isFixedOffset(): " + rules.isFixedOffset()); ZoneOffset offset = rules.getOffset(now); System.out.println("Zone offset: " + offset); List<ZoneOffsetTransition> transitions = rules.getTransitions(); System.out.println(transitions); }
From source file:Main.java
public static void main(String[] argv) { LocalDate today = LocalDate.now(); System.out.println(String.format("Year : %s Month : %s day : %s", today.getYear(), today.getMonthValue(), today.getDayOfMonth()));/*from w ww. ja v a 2 s . c o m*/ LocalDateTime time = LocalDateTime.now(); System.out.println( String.format("Hour : %s Mins : %s Sec : %s", time.getHour(), time.getMinute(), time.getSecond())); }
From source file:Main.java
public static void main(String[] args) { DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM, FormatStyle.SHORT);//from www. j ava 2 s .c o m System.out.println(dateTimeFormatter.format(LocalDateTime.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); }