1String pattern = "yyyy-MM-dd";
2SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
3
4String date = simpleDateFormat.format(new Date());
5System.out.println(date);
6
1String pattern = "yyyy-MM-dd";
2SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
3
4Date date = simpleDateFormat.parse("2018-09-09");
5
1String pattern = "EEEEE dd MMMMM yyyy HH:mm:ss.SSSZ";
2SimpleDateFormat simpleDateFormat =
3 new SimpleDateFormat(pattern, new Locale("da", "DK"));
4
5String date = simpleDateFormat.format(new Date());
6System.out.println(date);
7
1Locale locale = new Locale("en", "UK");
2DateFormatSymbols dateFormatSymbols = new DateFormatSymbols(locale);
3dateFormatSymbols.setWeekdays(new String[]{
4 "Unused",
5 "Sad Sunday",
6 "Manic Monday",
7 "Thriving Tuesday",
8 "Wet Wednesday",
9 "Total Thursday",
10 "Fat Friday",
11 "Super Saturday",
12});
13
14String pattern = "EEEEE MMMMM yyyy";
15SimpleDateFormat simpleDateFormat =
16 new SimpleDateFormat(pattern, dateFormatSymbols);
17
18String date = simpleDateFormat.format(new Date());
19System.out.println(date);
20
1DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
2
3try {
4 LocalDate date = formatter.parse(text, LocalDate::from);
5} catch (DateTimeParseException e) {
6 // Thrown if text could not be parsed in the specified format
7}
8