Date & Time API: Java SE
Date & Time API: Java SE
Java SE
Contents
• Instant
• Date Classes
System.out.println(timeStamp);
System.out.println(oneHourLater);
• LocalDate
• YearMonth
• MonthDay
• Year
LocalDate
• LocalDate အ*: Year-Month-Day =ဖင$6eဖ*$=ပeသ*: အခ/iန$ မပ'ဝင$
eသ*: ISO Calendar ရက$စ"8မ/*:အ*: ကiuယ$စ*:=ပuရ*တ"င$ အသu:< =ပu၏
System.out.println(memorialDay);
System.out.println(nextWed);
YearMonth
• သတ$မ5တ$ထ*:eသ* ?5စ$တစ$?5စ$၏ လအ*:ကiuယ$စ*:=ပuရ*တ"င$ YearMonth အ*: အသu<:=ပuHက၏
System.out.println(day.isValidYear(2010));
System.out.println(day.isValidYear(2012));
Year
• ?5စ$အ*:ကiuယ$စ*:=ပuရန$ Year အ*: အသu:< =ပuHက၏
• LocalTime
အခ/iန$အ*: ကiuယ$စ*:=ပueသ* Class =ဖစ$၏
• LocalDateTime
ရက$စ"8န5င$6 အခ/iန$အ* တ"8Qပ4:အသu<:=ပuရ*တ"င$ သu<:?iuင$eသ*
Class =ဖစ$၏
LocalTime
System.out.println(time1);
System.out.println(time2);
System.out.println(time3);
LocalDateTime
// 2015-03-19T00:52:55.299
LocalDateTime day1 = LocalDateTime.now();
// 2015-01-28T00:00
LocalDateTime day2 = LocalDateTime.of
(LocalDate.of(2015, Month.JANUARY, 28), LocalTime.MIDNIGHT);
// 2015-03-19T00:52:55.301
LocalDateTime day3 = LocalDateTime.
ofInstant(Instant.now(), ZoneId.systemDefault());
// 2010-02-20T18:30
LocalDateTime day4 = LocalDateTime.of(2010, 2, 20, 18, 30);
Time Zone Specific Classes
• Interpretation
• Changing Value
• now
• of
• ofYearDay
• parse
Creation
// local date time
System.out.format("%s : %s%n", "Local DateTime", LocalDateTime.now());
// local date
System.out.format("%s : %s%n", "Local Date", LocalDate.now());
// local time
System.out.format("%s : %s%n", "Local Time", LocalTime.now());
// local date of
System.out.format("%s : %s%n", "Date of", LocalDate.of(2013, 10, 12));
System.out.format("%s : %s%n", "Date of", LocalDate.of(2013, Month.APRIL, 12));
System.out.format("%s : %s%n", "Year of day ", LocalDate.ofYearDay(2013, 150));
System.out.format("%s : %s%n", "Parse Date", LocalDate.parse("2014-10-11"));
// local time of
System.out.format("%s : %s%n", "Time of", LocalTime.of(17, 10, 12));
System.out.format("%s : %s%n", "Parse Time", LocalTime.parse("15:30:00"));
• getDayOfWeek • getHour
• getDayOfMonth • getMinute
• getDayOfYear • getSecond
• getYear • getNano
• getMonth
• getMonthValue • isAfter
• isBefore
• isLeapYear
Interpretation
LocalDateTime now = LocalDateTime.now();
System.out.format("%s : %d%n", "DayOfMonth", now.getDayOfMonth());
System.out.format("%s : %s%n", "DayOfWeek", now.getDayOfWeek());
System.out.format("%s : %d%n", "DayOfYear", now.getDayOfYear());
System.out.format("%s : %d%n", "Hour", now.getHour());
System.out.format("%s : %d%n", "Minute", now.getMinute());
System.out.format("%s : %s%n", "Month", now.getMonth());
System.out.format("%s : %d%n", "MonthValue", now.getMonthValue());
System.out.format("%s : %d%n", "Nano", now.getNano());
System.out.format("%s : %d%n", "Second", now.getSecond());
System.out.format("%s : %d%n", "Year", now.getYear());
• အခ/iန$က*လအတiuင$:အတ*အ*: eဖ*$=ပလiueသ*အခ'
Period ?5င$6 Duration အ*:အသu<:=ပuရ၏