Obtains an instance of ZoneId from an ID ensuring that the ID is valid and available for use. This method parses the ID producing a ZoneId or ZoneOffset. A ZoneOffset is returned if the ID is 'Z', or starts with '+' or '-'. ZonedDateTime java.time.ZonedDateTime.of(LocalDateTime localDateTime, ZoneId zone)
Obtains an instance of ZonedDateTime from a local date-time. This creates a zoned date-time matching the input local date-time as closely as possible. Time-zone rules, such as daylight savings, mean that not every local date-time is valid for the specified zone, thus the local date-time may be adjusted.
ZoneOffset java.time.ZonedDateTime.getOffset()
Gets the zone offset, such as '+01:00'. This is the offset of the local date-time from UTC/Greenwich
Question : You have been given below code, what behavior is expected?
class Welcome { public static void main(String[] args) { DateTimeFormatter dateFormat = DateTimeFormatter.ISO_DATE; LocalDate dateOfBirth = LocalDate.of(2016, Month.FEBRUARY, 29); System.out.println(dateFormat.format(dateOfBirth)); } } 1. It will give compile time error.
The ISO date formatter that formats or parses a date with the offset if available, such as '2011-12-03' or '2011-12-03+01:00'. This returns an immutable formatter capable of formatting and parsing the ISO-8601 extended date format. The format consists of: LocalDate java.time.LocalDate.of(int year, Month month, int dayOfMonth)
Obtains an instance of LocalDate from a year, month and day. This returns a LocalDate with the specified year, month and day-of-month. The day must be valid for the year and month, otherwise an exception will be thrown. Parameters: year the year to represent, from MIN_YEAR to MAX_YEAR month the month-of-year to represent, not null dayOfMonth the day-of-month to represent, from 1 to 31
Formats a date-time object using this formatter. This formats the date-time to a String using the rules of the formatter. Parameters: temporal the temporal object to format, not null
Question : You have been given following code, and running from a system which are installed in India on Saturday and month is November and Year is . What will be the behavior of the code? package com.hadoopexam;
class Welcome { public static void main(String[] args) { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("EEEE",Locale.US); System.out.println(formatter.format(LocalDateTime.now())); } } 1. It will not compile.
Correct Answer : Get Lastest Questions and Answer : Explanation: E is the day name in the week; the pattern "EEEE" prints the name of the day in its full format. "Sat" is a short form that would be printed by the pattern "E", but "EEEE" prints the day of the week in full form: for example, "Saurday". Because the locale is Locale.US, the result is printed in English.
Creates a formatter using the specified pattern and locale. This method will create a formatter based on a simple pattern of letters and symbols as described in the class documentation. For example, d MMM uuuu will format 2011-12-03 as '3 Dec 2011'. The formatter will use the specified locale. This can be changed using DateTimeFormatter.withLocale(Locale) on the returned formatter The returned formatter has no override chronology or zone. It uses SMART resolver style. String java.time.format.DateTimeFormatter.format(TemporalAccessor temporal)
Formats a date-time object using this formatter. This formats the date-time to a String using the rules of the formatter. Parameters: temporal the temporal object to format, not null Returns: the formatted string, not null