240.
241.
DateTimeFormatter instance in addition to the String date. A
DateTimeFormatter can be created via the static
DateTimeFormatter.ofPattern() method. This method
accepts as parameter a String corresponding
to the desired data
format. Here, the code creates a DateTimeFormatter that can
parse a date in the
yyyy/mm/dd format. So,
this code prints the
output shown below:
2012–10–11
What is the output of the following code snippet?
LocalDateTime dateTime = LocalDateTime.parse(“2014–12–
28T08–45–00”);
dateTime = dateTime.withYear(1998);
System.out.println(dateTime);
Answer:
The code above first creates a LocalDateTime instance. It then
invokes the dateTime.withYear() method. This method
updates the year component on the LocalDateTime on which it
is invoked to the specified year. So,
in this case, it updates the
year in dateTime to
1998 and
assigns the result
to the dateTime object. So, this code prints the output shown
below:
1998–12–28T08–45
Do'stlaringiz bilan baham: