235.
236.
isBefore–false
Explain the ZonedDateTime class.
Answer:
The ZonedDateTime class represents
a date and time that also
has a time–zone information. So, in addition to the year, month,
day, hour, minutes, seconds
and nano seconds components, it
also has a ZoneId component. The ZoneId is an instance of the
java.time.ZoneId and represents the time–zone. There are
about 40 time zones that can be represented via a Zone Id. The
code below shows how you can create a ZonedDateTime:
ZoneId zoneId = ZoneId.of(“Asia/Kolkata”);
ZonedDateTime zonedDateTime = ZonedDateTime.now(zoneId);
So, the above code snippet first creates a ZoneId corresponding
to
Asia/Calcutta which is the IST time–zone.
It then creates a
ZonedDateTime that corresponding to the current time as per
the system clock but with this zone id.
What will be the output of the following code snippet?
LocalTime localTime = LocalTime.of(7, 15);
System.out.println(localTime.minusMinutes(30));
Answer:
The above code creates a LocalTime instance.
A LocalTime
represents time that has the hours, minutes,
seconds and
nanoseconds component. Here a LocalTime object is created
corresponding to
7–15.
The code then invokes the
minusMinutes() method with the value
30 and
prints the
output. The minusMinutes() method subtracts the specified