Guest User

Untitled

a guest
Sep 21st, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. import java.time.*;
  2. import java.time.format.DateTimeFormatter;
  3. import java.time.format.FormatStyle;
  4. import java.time.Month;
  5.  
  6. //basic examples of the Java 8 Date and time API
  7.  
  8. public class Timing extends MyClass {
  9. public static void main(String[] args) {
  10. LocalDate date1 = LocalDate.of(2015, Month.JANUARY, 20);
  11. LocalDate date2 = LocalDate.of(2015, 1, 20);
  12.  
  13. LocalTime time1 = LocalTime.of(22, 00, 13, 1000001);
  14.  
  15. LocalDateTime dateTime1 = LocalDateTime.of(2015, Month.JANUARY, 20, 6, 15, 30);
  16.  
  17. Period period = Period.ofDays(5);
  18. date1 = date1.plus(period);
  19.  
  20. Duration d = Duration.ofMinutes(100);
  21. time1 = time1.minus(d);
  22.  
  23. LocalDate date = LocalDate.of(2020, Month.JANUARY, 20);
  24. LocalTime time = LocalTime.of(11, 12, 34);
  25. LocalDateTime fromObjects = LocalDateTime.of(date, time);
  26. System.out.println(date.format(DateTimeFormatter.ISO_LOCAL_DATE));
  27. System.out.println(time.format(DateTimeFormatter.ISO_LOCAL_TIME));
  28. System.out.println(fromObjects.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
  29.  
  30. DateTimeFormatter shortDateTime = DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM);
  31. System.out.println(shortDateTime.format(fromObjects));
  32. System.out.println(shortDateTime.format(date1));
  33. }
  34. }
Add Comment
Please, Sign In to add comment