public class LocalDateTimeClass { public static void main(String[] args) { LocalDateTime now = LocalDateTime.now(); System.out.println("Before Formatting: " + now); DateTimeFormatter format = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss"); String formatDateTime = now.format(format); System.out.println("After Formatting: " + formatDateTime); // now() LocalDateTime datetime1 = LocalDateTime.now(); DateTimeFormatter format1 = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss"); String formatDateTime1= datetime1.format(format1); System.out.println(formatDateTime1); // get() LocalDateTime a = LocalDateTime.of(2017, 2, 13, 15, 56); System.out.println(a.get(ChronoField.DAY_OF_WEEK)); System.out.println(a.get(ChronoField.DAY_OF_YEAR)); System.out.println(a.get(ChronoField.DAY_OF_MONTH)); System.out.println(a.get(ChronoField.HOUR_OF_DAY)); System.out.println(a.get(ChronoField.MINUTE_OF_DAY)); //minusDay() LocalDateTime datetime2 = LocalDateTime.of(2017, 1, 14, 10, 34); LocalDateTime datetime3 = datetime2.minusDays(100); System.out.println("Before Formatting: " + datetime2); DateTimeFormatter format2 = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm"); String formatDateTime2 = datetime3.format(format2); System.out.println("After Formatting: " + formatDateTime2 ); // plusDay() LocalDateTime datetime4 = LocalDateTime.of(2017, 1, 14, 10, 34); LocalDateTime datetime5 = datetime4.plusDays(120); System.out.println("Before Formatting: " + datetime5); DateTimeFormatter format3 = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm"); String formatDateTime3 = datetime2.format(format3); System.out.println("After Formatting: " + formatDateTime3 ); } }
Thursday, 9 February 2017
Date : LocalDateTimeClass
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment