Advanced Java Programming: Topic: Date Time API
Advanced Java Programming: Topic: Date Time API
They are local in the sense that they represent date and time
from the context of one observer, in contrast to time zones.
All the core classes in the new API are constructed by
factory methods.
When constructing a value through its fields, the factory is
called of.
There are also parse methods that take strings as parameters:
LocalDate
Methods
public static LocalDate now()
public static LocalDate now(ZoneID id)
Methods:
public static DateTimeFormatter ofPattern(String pattern)
public static DateTimeFormatter ofLocalizedDate(FormatStyle
dateStyle)
DateTimeFormatter
Pattern Symbols
Symbol Meaning Presentation Examples
M/L month-of-year number/text 7; 07; Jul; July; J
d day-of-month number 10
y year-of-era year 2004; 04
H hour-of-day (0-23) number 0
m minute-of-hour number 30
s second-of-minute number 55
S fraction-of-second fraction 978
E day-of-week text Tue; Tuesday;
V time-zone ID zone-id America/Los_Angeles;
Z; -08:30
a am-pm-of-day text PM
DateTimeFormatter
Constants:
public static final DateTimeFormatter ISO_LOCAL_DATE;
public static final DateTimeFormatter ISO_ORDINAL_DATE;
DateTimeFormatter
ZonedDateTime now = ZonedDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE;
System.out.println(now.format(formatter));
formatter = DateTimeFormatter.ISO_ORDINAL_DATE;
System.out.println(now.format(formatter));
FormatStyle values:
SHORT
MEDIUM
LONG
FULL
DateTimeFormatter
ZonedDateTime now = ZonedDateTime.now();
DateTimeFormatter formatter =
DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM);
System.out.println(now.format(formatter));