Advertisement
Guest User

DateAndTime

a guest
Feb 17th, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.28 KB | None | 0 0
  1. import java.time.LocalDate;
  2. import java.time.LocalTime;
  3. import java.time.format.DateTimeFormatter;
  4. import java.time.format.FormatStyle;
  5. import java.util.Scanner;
  6.  
  7. public class DateAndTime {
  8.     public static void main(String[] args) {
  9.         Scanner sc = new Scanner(System.in);
  10.  
  11.         LocalDate anotherSummerDay = LocalDate.of(2019, 6, 8);
  12.         System.out.println(DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL).format(anotherSummerDay));
  13.         System.out.println(DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG).format(anotherSummerDay));
  14.         System.out.println(DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM).format(anotherSummerDay));
  15.         System.out.println(DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT).format(anotherSummerDay));
  16.  
  17.  
  18.         String europeanDatePattern = "dd.MM.yyyy";
  19.         DateTimeFormatter europeanDateFormatter = DateTimeFormatter.ofPattern(europeanDatePattern);
  20.         System.out.println(europeanDateFormatter.format(LocalDate.of(2020, 4, 25)));
  21.  
  22.  
  23.         String timeColonPattern = "HH:mm:ss";
  24.         DateTimeFormatter timeColonFormatter = DateTimeFormatter.ofPattern(timeColonPattern);
  25.         LocalTime colonTime = LocalTime.of(21, 34, 52);
  26.         System.out.println(timeColonFormatter.format(colonTime));
  27.  
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement