hereral/Clara-Training-Data huggingface dataset:
Question: What are the Drawbacks of existing Date/Time API's?
Answer: -Thread safety: The existing classes such as Date and Calendar does not provide thread safety. Hence it leads to hard-to-debug concurrency issues that are needed to be taken care by developers. The new Date and Time APIs of Java 8 provide thread safety and are immutable, hence avoiding the concurrency issue from developers.
-Bad API designing: The classic Date and Calendar APIs does not provide methods to perform basic day-to-day functionalities. The Date and Time classes introduced in Java 8 are ISO-centric and provides number of different methods for performing operations regarding date, time, duration and periods.
-Difficult time zone handling: To handle the time-zone using classic Date and Calendar classes is difficult because the developers were supposed to write the logic for it. With the new APIs, the time-zone handling can be easily done with Local and ZonedDate/Time APIs.
Question: What are the following classes in New Date Time API in Java 8?
Answer: The new date API helps to overcome the drawbacks mentioned above with the legacy classes. It includes the following classes:

java.time.LocalDate: It represents a year-month-day in the ISO calendar and is useful for representing a date without a time. It can be used to represent a date only information such as a birth date or wedding date.

java.time.LocalTime: It deals in time only. It is useful for representing human-based time of day, such as movie times, or the opening and closing times of the local library.

java.time.LocalDateTime: It handles both date and time, without a time zone. It is a combination of LocalDate with LocalTime.

java.time.ZonedDateTime: It combines the LocalDateTime class with the zone information given in ZoneId class. It represent a complete date time stamp along with timezone information.

java.time.OffsetTime: It handles time with a corresponding time zone offset from Greenwich/UTC, without a time zone ID.

java.time.OffsetDateTime: It handles a date and time with a corresponding time zone offset from Greenwich/UTC, without a time zone ID.

java.time.Clock : It provides access to the current instant, date and time in any given time-zone. Although the use of the Clock class is optional, this feature allows us to test your code for other time zones, or by using a fixed clock, where time does not change.

java.time.Instant : It represents the start of a nanosecond on the timeline (since EPOCH) and useful for generating a timestamp to represent machine time. An instant that occurs before the epoch has a negative value, and an instant that occurs after the epoch has a positive value.

java.time.Duration : Difference between two instants and measured in seconds or nanoseconds and does not use date-based constructs such as years, months, and days, though the class provides methods that convert to days, hours, and minutes.

java.time.Period : It is used to define the difference between dates in date-based values (years, months, days).

java.time.ZoneId : It states a time zone identifier and provides rules for converting between an Instant and a LocalDateTime.

java.time.ZoneOffset : It describe a time zone offset from Greenwich/UTC time.

java.time.format.DateTimeFormatter : It comes up with various predefined formatter, or we can define our own. It has parse() or format() method for parsing and formatting the date time values.
Question: What is Java LocalDate class?
Answer: Java LocalDate class is an immutable class that represents Date with a default format of yyyy-mm-dd. It inherits Object class and implements the ChronoLocalDate interface
Question: What is Java LocalDate class declaration?
Answer: Let's see the declaration of java.time.LocalDate class.

public final class LocalDate extends Object   
implements Temporal, TemporalAdjuster, ChronoLocalDate, Serializable
Question: What are the Methods of Java LocalDate?
Answer: Methods of Java LocalDate

Method: LocalDateTime atTime(int hour, int minute)
Description: It is used to combine this date with a time to create a LocalDateTime.

Method: int compareTo(ChronoLocalDate other)
Description: It is used to compares this date to another date.

Method: boolean equals(Object obj)
Description: It is used to check if this date is equal to another date.

Method: String format(DateTimeFormatter formatter)
Description: It is used to format this date using the specified formatter.

Method: int get(TemporalField field)
Description: It is used to get the value of the specified field from this date as an int.

Method: boolean isLeapYear()
Description: It is used to check if the year is a leap year, according to the ISO proleptic calendar system rules.

Method: LocalDate minusDays(long daysToSubtract)
Description: It is used to return a copy of this LocalDate with the specified number of days subtracted.



Method: LocalDate minusMonths(long monthsToSubtract)
Description: It is used to return a copy of this LocalDate with the specified number of months subtracted.
`
Method: static LocalDate now()
Description: It is used to obtain the current date from the system clock in the default time-zone.

Method: LocalDate plusDays(long daysToAdd)
Description: 
It is used to return a copy of this LocalDate with the specified number of days added.


Method: LocalDate plusMonths(long monthsToAdd)
Description: It is used to return a copy of this LocalDate with the specified number of months added.

Method: LocalDate plusMonths(long monthsToAdd)
Description: It is used to return a copy of this LocalDate with the specified number of months added.

Method: int getDayOfMonth()
Description: It gets the day-of-month field.

Method: DayOfWeek getDayOfWeek()
Description: It gets the day-of-week field, which is an enum DayOfWeek


Method: int getDayOfYear()
Description: It gets the day-of-year field.

Method: Month getMonth()
Description: It gets the month-of-year field using the Month enum.

Method: int getMonthValue()
Description: It gets the month-of-year field from 1 to 12.

Method: int getYear()
Description: It gets the year field.

Method: int lengthOfMonth()
Description: It returns the length of the month represented by this date.

Method: int lengthOfYear()
Description: It returns the length of the year represented by this date.

Method: static LocalDate ofYearDay(int year, int dayOfYear)
Description: It obtains an instance of LocalDate from a year and day-of-year.

Method: static LocalDate parse(CharSequence text)
Description: It obtains an instance of LocalDate from a text string such as 2007-12-03

Method: static LocalDate parse(CharSequence text, DateTimeFormatter formatter)
Description: It obtains an instance of LocalDate from a text string using a specific formatter.
Question: Can you provide an example of Java LocalDate?
Answer: Program to demonstrate methods of LocalDate class such as now(), minusDays(), plusDays().

LocalDateExample1.java

import java.time.LocalDate;    
public class LocalDateExample1 {    
  public static void main(String[] args) {    
    LocalDate date = LocalDate.now();    
    LocalDate yesterday = date.minusDays(1);    
    LocalDate tomorrow = yesterday.plusDays(2);    
    System.out.println("Today date: "+date);    
    System.out.println("Yesterday date: "+yesterday);    
    System.out.println("Tomorrow date: "+tomorrow);    
  }    
}    
Output:

Today date: 2017-01-13
Yesterday date: 2017-01-12
Tomorrow date: 2017-01-14
Question: What is Java LocalTime Class?
Answer: Java LocalTime class is an immutable class that represents time with a default format of hour-minute-second. It inherits Object class and implements the Comparable interface.
Question: What is Java LocalTime class declaration?
Answer: Let's see the declaration of java.time.LocalTime class.

public final class LocalTime extends Object   
implements Temporal, TemporalAdjuster, Comparable<LocalTime>, Serializable
Question: What are the Methods of Java LocalTime Class?
Answer: Methods of Java LocalTime Class
Method: LocalDateTime atDate(LocalDate date)
Description: It is used to combine this time with a date to create a LocalDateTime.

Method: int compareTo(LocalTime other)
Description: It is used to compare this time to another time.

Method: String format(DateTimeFormatter formatter)
Description: It is used to format this time using the specified formatter.

Method: int get(TemporalField field)
Description: It is used to get the value of the specified field from this time as an int.

Method: LocalTime minusHours(long hoursToSubtract)
Description: It is used to return a copy of this LocalTime with the specified number of hours subtracted.

Method: LocalTime minusMinutes(long minutesToSubtract)
Description: It is used to return a copy of this LocalTime with the specified number of minutes subtracted.

Method: static LocalTime now()
Description: It is used to obtain the current time from the system clock in the default time-zone.

Method: static LocalTime of(int hour, int minute, int second)
Description: It is used to obtain an instance of LocalTime from an hour, minute and second.

Method: LocalTime plusHours(long hoursToAdd)
Description: It is used to return a copy of this LocalTime with the specified number of hours added.

Method: LocalTime plusMinutes(long minutesToAdd)
Description: It is used to return a copy of this LocalTime with the specified number of minutes added.
Question: Can you provide an example of Java LocalTime: now()?
Answer: LocalTimeExample1.java

import java.time.LocalTime;  
public class LocalTimeExample1 {  
  public static void main(String[] args) {  
    LocalTime time = LocalTime.now();  
    System.out.println(time);  
  }  
}  

Output:

15:19:47.459
Question: Can you provide an example of Java LocalTime: of()?
Answer: LocalTimeExample2.java

import java.time.LocalTime;  
public class LocalTimeExample2 {  
  public static void main(String[] args) {  
    LocalTime time = LocalTime.of(10,43,12);  
    System.out.println(time);  
  }  
}  
Output:

10:43:12
Question: Can you provide an example of Java localtime minusHours() and minusMinutes()?
Answer: LocalTimeExample3.java

import java.time.LocalTime;  
public class LocalTimeExample3 {  
  public static void main(String[] args) {  
    LocalTime time1 = LocalTime.of(10,43,12);  
    System.out.println(time1);  
    LocalTime time2=time1.minusHours(2);  
    LocalTime time3=time2.minusMinutes(34);  
    System.out.println(time3);  
  }  
}  

Output:

10:43:12
08:09:12
Question: Can you provide an example of Java localtime : plusHours() and plusMinutes()?
Answer: LocalTimeExample5.java

import java.time.*;  
import java.time.temporal.ChronoUnit;  
public class LocalTimeExample5 {  
  public static void main(String... args) {  
    ZoneId zone1 = ZoneId.of("Asia/Kolkata");  
    ZoneId zone2 = ZoneId.of("Asia/Tokyo");  
    LocalTime time1 = LocalTime.now(zone1);  
    System.out.println("India Time Zone: "+time1);  
    LocalTime time2 = LocalTime.now(zone2);  
    System.out.println("Japan Time Zone: "+time2);  
    long hours = ChronoUnit.HOURS.between(time1, time2);  
    System.out.println("Hours between two Time Zone: "+hours);  
    long minutes = ChronoUnit.MINUTES.between(time1, time2);  
    System.out.println("Minutes between two time zone: "+minutes);  
  }  
}  

Output:

India Time Zone: 14:56:43.087
Japan Time Zone: 18:26:43.103
Hours between two Time Zone: 3
Minutes between two time zone: 210
Question: Can you provide an example of Java LocalTime?
Answer: import java.time.LocalTime;  
public class LocalTimeExample1 {  
  public static void main(String[] args) {  
    LocalTime time = LocalTime.now();  
    System.out.println(time);  
  }  
}  

Output:

15:19:47.459
Question: What is Java LocalDateTime class?
Answer: Java LocalDateTime class is an immutable date-time object that represents a date-time, with the default format as yyyy-MM-dd-HH-mm-ss.zzz. It inherits object class and implements the ChronoLocalDateTime interface.
Question: What is Java LocalDateTime class declaration?
Answer: Let's see the declaration of java.time.LocalDateTime class.

public final class LocalDateTime extends Object   
implements Temporal, TemporalAdjuster, ChronoLocalDateTime<LocalDate>, Serializable
Question: What are the Methods of Java local DateTime?
Answer: Methods of Java LocalDateTime
Method: String format(DateTimeFormatter formatter)
Description: It is used to format this date-time using the specified formatter.

Method: int get(TemporalField field)
Description: It is used to get the value of the specified field from this date-time as an int.

Method: LocalDateTime minusDays(long days)
Description: It is used to return a copy of this LocalDateTime with the specified number of days subtracted.


Method: static LocalDateTime now()
Description: It is used to obtain the current date-time from the system clock in the default time-zone.

Method: static LocalDateTime of(LocalDate date, LocalTime time)
Description: It is used to obtain an instance of LocalDateTime from a date and time.

Method: LocalDateTime plusDays(long days)
Description: It is used to return a copy of this LocalDateTime with the specified number of days added.

Method: boolean equals(Object obj)
Description: It is used to check if this date-time is equal to another date-time.
Question: Can you provide an example of Java localDateTime?
Answer: import java.time.LocalDateTime;  
import java.time.format.DateTimeFormatter;  
public class LocalDateTimeExample1 {  
    public static void main(String[] args) {  
        LocalDateTime now = LocalDateTime.now();  
        System.out.println("Before Formatting: " + now);  
        DateTimeFormatter format = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss");  
        String formatDateTime = now.format(format);  
        System.out.println("After Formatting: " + formatDateTime);  
    }  
}  

Output:

Before Formatting: 2017-01-13T17:09:42.411
After Formatting: 13-01-2017 17:09:42
Question: Can you provide an example of Java localDateTime: now()?
Answer: import java.time.LocalDateTime;  
import java.time.format.DateTimeFormatter;  
public class LocalDateTimeExample2 {  
  public static void main(String[] args) {  
    LocalDateTime datetime1 = LocalDateTime.now();  
    DateTimeFormatter format = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss");  
    String formatDateTime = datetime1.format(format);   
    System.out.println(formatDateTime);    
  }  
}  
Output:

14-01-2017 11:42:32
Question: Java LocalDateTime Example: get() Can you provide an example of Java localDateTime: get()?
Answer: import java.time.LocalDateTime;  
import java.time.temporal.ChronoField;  
public class LocalDateTimeExample3 {  
  public static void main(String[] args) {  
    LocalDateTime a = LocalDateTime.of(2017, 2, 13, 15, 56);    
    System.out.println(a.get(ChronoField.DAY_OF_WEEK));  
    System.out.println(a.get(ChronoField.DAY_OF_YEAR));  
    System.out.println(a.get(ChronoField.DAY_OF_MONTH));  
    System.out.println(a.get(ChronoField.HOUR_OF_DAY));  
    System.out.println(a.get(ChronoField.MINUTE_OF_DAY));   
  }  
}  
Output:

1
44
13
15
956
Question: Can you provide an example of Java localDateTime: minusDays()?
Answer: import java.time.LocalDateTime;  
import java.time.format.DateTimeFormatter;  
public class LocalDateTimeExample4 {  
public static void main(String[] args) {  
  LocalDateTime datetime1 = LocalDateTime.of(2017, 1, 14, 10, 34);  
  LocalDateTime datetime2 = datetime1.minusDays(100);  
  System.out.println("Before Formatting: " + datetime2);  
  DateTimeFormatter format = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm");  
  String formatDateTime = datetime2.format(format);   
  System.out.println("After Formatting: " + formatDateTime );  
}  
}  

Output:

Before Formatting: 2016-10-06T10:34
After Formatting: 06-10-2016 10:34
Question: Can you provide an example of Java localDateTime: plusDays()?

Answer: import java.time.LocalDateTime;  
import java.time.format.DateTimeFormatter;  
public class LocalDateTimeExample5 {  
public static void main(String[] args) {  
  LocalDateTime datetime1 = LocalDateTime.of(2017, 1, 14, 10, 34);  
  LocalDateTime datetime2 = datetime1.plusDays(120);  
  System.out.println("Before Formatting: " + datetime2);  
  DateTimeFormatter format = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm");  
  String formatDateTime = datetime2.format(format);   
  System.out.println("After Formatting: " + formatDateTime );  
}  
}  

Output:

Before Formatting: 2017-05-14T10:34
After Formatting: 14-05-2017 10:34
Question: What is Java MonthDay Class?
Answer: Java MonthDay class is an immutable date-time object that represents the combination of a month and day-of-month. It inherits Object class and implements the Comparable interface.
Question: What is Java MonthDay Class Declaration?
Answer: Let's see the declaration of java.time.MonthDay class.

public final class MonthDay extends Object   
implements TemporalAccessor, TemporalAdjuster, Comparable<MonthDay>, Serializable
Question: What are the Methods of Java MonthDay Class?
Answer: Methods of Java MonthDay Class
Method: LocalDate atYear(int year)
Description: It is used to combine this month-day with a year to create a LocalDate.

Method: String format(DateTimeFormatter formatter)
Description: It is used to format this month-day using the specified formatter.

Method: int get(TemporalField field)
Description: It is used to get the value of the specified field from this month-day as an int.

Method: boolean isValidYear(int year)
Description: It is used to check if the year is valid for this month-day.

Method: static MonthDay now()
Description: It is used to obtain the current month-day from the system clock in the default time-zone.

Method: static MonthDay of(int month, int dayOfMonth)
Description: It is used to obtain an instance of MonthDay.

Method: ValueRange range(TemporalField field)
Description: It is used to get the range of valid values for the specified field.

Method: int getDayOfMonth()
Description: It gets the day-of-month field.

Method: Month getMonth()
Description: It gets the month-of-year field using the Month enum.

Method: int getMonthValue()
Description: It gets the month-of-year field from 1 to 12.

Method: int hashCode()
Description: It returns a hash code for this month-day.

Method: boolean isAfter(MonthDay other)
Description: It checks if this month-day is after the specified month-day.

Method: static MonthDay now()
Description: It obtains the current month-day from the system clock in the default time-zone.

Method: static MonthDay now(Clock clock)
Description: It obtains the current month-day from the specified clock.

Method: static MonthDay of(int month, int dayOfMonth)
Description: It obtains an instance of MonthDay.

Method: R query(TemporalQuery query)
Description: It queries this month-day using the specified query.

Method: ValueRange range(TemporalField field)
Description: It gets the range of valid values for the specified field.

Method: String toString()
Description: It outputs this month-day as a String, such as -12-03.

Method: MonthDay with(Month month)
Description: It returns a copy of this MonthDay with the month-of-year altered.

Method: MonthDay withDayOfMonth(int dayOfMonth)
Description: It returns a copy of this MonthDay with the day-of-month altered.

Method: MonthDay withMonth(int month)
Description: It returns a copy of this MonthDay with the month-of-year altered.
Question: Can you provide an example of Java MonthDay Class?
Answer: MonthDayExample1.java

import java.time.*;  
public class MonthDayExample1 {  
  public static void main(String[] args) {  
    MonthDay month = MonthDay.now();  
    LocalDate date = month.atYear(1994);  
    System.out.println(date);  
  }  
}  

Output:

1994-01-17
Question: Can you provide an example of  Java MonthDay Class: isValidYear()?
Answer: MonthDayExample2.java

import java.time.*;  
public class MonthDayExample2 {  
  public static void main(String[] args) {  
    MonthDay month = MonthDay.now();  
    boolean b = month.isValidYear(2012);  
    System.out.println(b);  
  }  
}  

Output:

true
Question: Can you provide an example of  Java MonthDay Class: get()?
Answer: MonthDayExample3.java

import java.time.*;  
import java.time.temporal.*;  
public class MonthDayExample3{  
  public static void main(String[] args) {  
    MonthDay month = MonthDay.now();  
    long n = month.get(ChronoField.MONTH_OF_YEAR);  
    System.out.println(n);  
  }  
}  

Output:

1
Question: Can you provide an example of Java MonthDay Class: range()?
Answer: MonthDayExample4.java

import java.time.*;  
import java.time.temporal.*;  
public class MonthDayExample4 {  
  public static void main(String[] args) {  
    MonthDay month = MonthDay.now();  
    ValueRange r1 = month.range(ChronoField.MONTH_OF_YEAR);  
    System.out.println(r1);  
    ValueRange r2 = month.range(ChronoField.DAY_OF_MONTH);  
    System.out.println(r2);  
  }  
}  
Output:

1 - 12
1 - 31
Question: What is Java OffsetTime Class Declaration?
Answer: Let's see the declaration of java.time.OffsetTime class.

public final class OffsetTime extends Object   
implements Temporal, TemporalAdjuster, Comparable<OffsetTime>, Serializable
Question: What are the Methods of Java OffsetTime Class?

Answer: Methods of Java OffsetTime Class
Method: String format(DateTimeFormatter formatter)
Description: It is used to format this time using the specified formatter.

Method: int get(TemporalField field)
Description: It is used to get the value of the specified field from this time as an int.

Method: int getHour()
Description: It is used to get the hour-of-day field.

Method: int getMinute()
Description: It is used to get the minute-of-hour field.

Method: int getSecond()
Description: It is used to get the second-of-minute field.

Method: static OffsetTime now()
Description: It is used to obtain the current time from the system clock in the default time-zone.

Method: static OffsetTime of(LocalTime time, ZoneOffset offset)
Description: It is used to obtain an instance of OffsetTime from a local time and an offset.

Method: ValueRange range(TemporalField field)
Description: It is used to get the range of valid values for the specified field.

Method: VLocalTime toLocalTime()
Description: It is used to get the LocalTime part of this date-time.

Method: boolean isAfter(OffsetTime other)
Description: It checks if the instant of this OffsetTime is after that of the specified time applying both times to a common date.

Method: boolean isBefore(OffsetTime other)
Description: It checks if the instant of this OffsetTime is before that of the specified time applying both times to a common date.

Method: boolean isEqual(OffsetTime other)
Description: It checks if the instant of this OffsetTime is equal to that of the specified time applying both times to a common date.

Method: boolean isSupported(TemporalField field)
Description: It checks if the specified field is supported.

Method: OffsetTime minus(long amountToSubtract, TemporalUnit unit)
Description: It returns a copy of this time with the specified amount subtracted.

Method: OffsetTime minus(TemporalAmount amountToSubtract)
Description: It returns a copy of this time with the specified amount subtracted.

Method: OffsetTime minusHours(long hoursToSubtract)
Description: It returns a copy of this OffsetTime with the specified number of hours subtracted.

Method: OffsetTime minusMinutes(long minutesToSubtract)
Description: It returns a copy of this OffsetTime with the specified number of minutes subtracted.

Method: OffsetTime minusNanos(long nanos)
Description: It returns a copy of this OffsetTime with the specified number of nanoseconds subtracted.

Method: OffsetTime minusSeconds(long seconds)
Description: It returns a copy of this OffsetTime with the specified number of seconds subtracted.

Method: static OffsetTime of(int hour, int minute, int second, int nanoOfSecond, ZoneOffset offset)
Description: It obtains an instance of OffsetTime from an hour, minute, second, nanosecond and an offset.

Method: static OffsetTime parse(CharSequence text, DateTimeFormatter formatter)
Description: It obtains an instance of OffsetTime from a text string using a specific formatter.
Question: Can you provide an example of Java OffsetTime class?

Answer: OffsetTimeExample1.java

import java.time.OffsetTime;  
import java.time.temporal.ChronoField;  
public class OffsetTimeExample1 {  
  public static void main(String[] args) {  
    OffsetTime offset = OffsetTime.now();  
    int h = offset.get(ChronoField.HOUR_OF_DAY);  
    System.out.println(h);  
    int m = offset.get(ChronoField.MINUTE_OF_DAY);  
    System.out.println(m);  
    int s = offset.get(ChronoField.SECOND_OF_DAY);  
    System.out.println(s);  
  }  
}  

Output:

16
970
58224
Question: What is Java OffsetDateTime Class?

Answer: Java OffsetDateTime class is an immutable representation of a date-time with an offset. It inherits Object class and implements the Comparable interface.

OffsetDateTime class is used to store the date and time fields, to a precision of nanoseconds.
Question: What is the class declaration for Java OffsetDateTime?
Answer: Let's see the declaration of java.time.OffsetDateTime class.

public final class OffsetDateTime extends Object   
implements Temporal, TemporalAdjuster, Comparable<OffsetDateTime>, Serializable
Question: What are the Methods of Java OffsetDateTime Class?
Answer: Java OffsetDateTime class is an immutable representation of a date-time with an offset. It inherits Object class and implements the Comparable interface.

OffsetDateTime class is used to store the date and time fields, to a precision of nanoseconds.
Question: Can you provide an example of Java OffsetDateTime Class?
 
Answer: import java.time.OffsetDateTime;  
public class OffsetDateTimeExample1 {  
    public static void main(String[] args) {  
        OffsetDateTime offsetDT = OffsetDateTime.now();  
        System.out.println(offsetDT.getDayOfMonth());  
    }  
}  

Output:
18
Question: What is Java Clock class?

Answer: Java Clock class is used to provide an access to the current, date and time using a time zone. It inherits the Object class.

Because all date-time classes contain a now() function that uses the system clock in the default time zone, using the Clock class is not required. The aim of the Clock class is to allow you to plug in another clock whenever you need it. Instead of using a static method, applications utilise an object to get the current time. It simplifies the testing process. A method that requires a current instant can take a Clock as a parameter.
Question: What is the class declaration for Java Clock class?
Answer: Let's see the declaration of java.time.Clock class.

public abstract class Clock extends Object
Question: Can you provide an example of Java OffsetDateTime Class: getDayOfMonth()?

Answer: OffsetDateTimeExample1.java

import java.time.OffsetDateTime;  
public class OffsetDateTimeExample1 {  
    public static void main(String[] args) {  
        OffsetDateTime offsetDT = OffsetDateTime.now();  
        System.out.println(offsetDT.getDayOfMonth());  
    }  
}  

Output:
18
Question: Can you provide an example of Java OffsetDateTime Class: getDayOfYear()?
Answer: OffsetDateTimeExample2.java

import java.time.OffsetDateTime;  
public class OffsetDateTimeExample2 {  
    public static void main(String[] args) {  
        OffsetDateTime offsetDT = OffsetDateTime.now();  
        System.out.println(offsetDT.getDayOfYear());  
    }  
}  

Output:

18
Question: Can you provide an example of Java OffsetDateTime Class:  getDayOfWeek()?
Answer: OffsetDateTimeExample3.java

import java.time.OffsetDateTime;  
public class OffsetDateTimeExample3 {  
    public static void main(String[] args) {  
        OffsetDateTime offsetDT = OffsetDateTime.now();  
        System.out.println(offsetDT.getDayOfWeek());  
    }  
}  

Output:

WEDNESDAY
Question: Can you provide an example of Java OffsetDateTime Class:  toLocalDate()?

Answer: OffsetDateTimeExample4.java

import java.time.OffsetDateTime;  
public class OffsetDateTimeExample4 {  
    public static void main(String[] args) {  
        OffsetDateTime offsetDT = OffsetDateTime.now();  
        System.out.println(offsetDT.toLocalDate());  
    }  
}  

Output:

2017-01-18
Question: Can you provide an example of Java OffsetDateTime Class:  minusDays()?

Answer: OffsetDateTimeExample5.java

import java.time.OffsetDateTime;  
public class OffsetDateTimeExample5 {  
  public static void main(String[] args) {  
    OffsetDateTime offset = OffsetDateTime.now();  
    OffsetDateTime value =  offset.minusDays(240);  
    System.out.println(value);  
  }   
}  

Output:

2016-05-23T12:12:31.642+05:30
Question: Can you provide an example of Java OffsetDateTime Class:  plusDays()?

Answer: OffsetDateTimeExample6.java

import java.time.OffsetDateTime;  
public class OffsetDateTimeExample6 {  
  public static void main(String[] args) {  
    OffsetDateTime offset = OffsetDateTime.now();  
    OffsetDateTime value =  offset.plusDays(240);  
    System.out.println(value);  
  }  
}  

Output:

2017-09-15T13:50:30.526+05:30
Question: What is Java Clock class?

Answer: Java Clock class is used to provide an access to the current, date and time using a time zone. It inherits the Object class.

Because all date-time classes contain a now() function that uses the system clock in the default time zone, using the Clock class is not required. The aim of the Clock class is to allow you to plug in another clock whenever you need it. Instead of using a static method, applications utilise an object to get the current time. It simplifies the testing process. A method that requires a current instant can take a Clock as a parameter.
Question: What is the class declaration for Java Clock Class?

Answer: et's see the declaration of java.time.Clock class.

public abstract class Clock extends Object
Question: What are the Methods of Java Clock Class?

Answer: Methods of Java Clock Class

Method:	abstract ZoneId getZone()	
Description: It is used to get the time-zone being used to create dates and times.

Method:	abstract Instant instant()	
Description: It is used to get the current instant of the clock.

Method:	static Clock offset(Clock baseClock, Duration offsetDuration)	
Description: It is used to obtain a clock that returns instants from the specified clock with the specified duration added

Method:	static Clock systemDefaultZone()	
Description: It is used to obtain a clock that returns the current instant using the best available system clock, converting to date and time using the default time-zone.

Method:	static Clock systemUTC()	
Description: It is used to obtain a clock that returns the current instant using the best available system clock, converting to date and time using the UTC time zone.

Method:	boolean equals(Object obj)	
Description: It checks if this clock is equal to another clock.

Method:	static Clock fixed(Instant fixedInstant, ZoneId zone)	
Description: It obtains a clock that always returns the same instant.

Method:	static Clock system(ZoneId zone)	
Description: It obtains a clock that returns the current instant using best available system clock.

Method:	int hashCode()	
Description: It gets the time-zone being used to create dates and times.

Method:	long millis()	
Description: It gets the current millisecond instant of the clock.

Method:	static Clock tick(Clock baseClock, Duration tickDuration)	
Description: It obtains a clock that returns instants from the specified clock truncated to the nearest occurrence of the specified duration.

Method:	static Clock tickMinutes(ZoneId zone)	
Description: It obtains a clock that returns the current instant ticking in whole minutes using best available system clock.

Method:	static Clock tickSeconds(ZoneId zone)	
Description: It obtains a clock that returns the current instant ticking in whole seconds using best available system clock.

Method:	static Clock withZone(ZoneId zone)	
Description: It returns a copy of this clock with a different time-zone.
Question: Can you provide an example of Java Clock class: getZone()?

Answer: ClockExample1.java

import java.time.Clock;  
public class ClockExample1 {  
  public static void main(String[] args) {  
    Clock c = Clock.systemDefaultZone();      
    System.out.println(c.getZone());  
  }  
}  

Output:

Asia/Calcutta
Question: Can you provide an example of Java Clock class: instant()?

Answer: ClockExample2.java

import java.time.Clock;  
public class ClockExample2 {  
  public static void main(String[] args) {  
    Clock c = Clock.systemUTC();  
    System.out.println(c.instant());  
  }  
}  

Output:
2017-01-14T07:11:07.748Z
Question: Can you provide an example of Java Clock class: systemUTC()?

Answer: ClockExample3.java

import java.time.Clock;  
public class ClockExample3 {  
  public static void main(String[] args) {  
    Clock c = Clock.systemUTC();  
    System.out.println(c.instant());  
  }  
}  

Output:
2017-01-14T07:11:07.748Z
Question: Can you provide an example of Java Clock class: offset()?

Answer: ClockExample4.java

import java.time.Clock;  
import java.time.Duration;  
public class ClockExample4 {  
  public static void main(String[] args) {  
    Clock c = Clock.systemUTC();  
    Duration d = Duration.ofHours(5);  
    Clock clock = Clock.offset(c, d);    
    System.out.println(clock.instant());  
  }  
}  

Output:
2017-01-14T14:15:25.389Z
Question: What is Java ZonedDateTime class?

Answer: Java ZonedDateTime class is an immutable representation of a date-time with a time-zone. It inherits Object class and implements the ChronoZonedDateTime interface.

ZonedDateTime class is used to store all date and time fields, to a precision of nanoseconds, and a time-zone with a zone offset used to handle ambiguous local date-times.
Question: What is the class declaration for Java ZonedDateTime class?

Answer: Let's see the declaration of java.time.ZonedDateTime class.

public final class ZonedDateTime extends Object   
implements Temporal, ChronoZonedDateTime<LocalDate>, Serializable
Question: What are the Methods of Java ZonedDateTime?

Answer: Methods of Java ZonedDateTime

Method:	String format(DateTimeFormatter formatter)	
Description: It is used to format this date-time using the specified formatter.

Method: int get(TemporalField field)	
Description: It is used to get the value of the specified field from this date-time as an int.

Method: ZoneId getZone()	
Description: It is used to get the time-zone, such as 'Asia/Kolkata'.

Method: ZonedDateTime withZoneSameInstant(ZoneId zone)	
Description: It is used to return a copy of this date-time with a different time-zone, retaining the instant.

Method: static ZonedDateTime now()	
Description: It is used to obtain the current date-time from the system clock in the default time-zone.

Method: static ZonedDateTime of(LocalDate date, LocalTime time, ZoneId zone)	
Description: It is used to obtain an instance of ZonedDateTime from a local date and time.

Method: ZonedDateTime minus(long amountToSubtract, TemporalUnit unit)	
Description: It is used to return a copy of this date-time with the specified amount subtracted.

Method: ZonedDateTime plus(long amountToAdd, TemporalUnit unit)	
Description: It is used to return a copy of this date-time with the specified amount added.
Question: Can you provide an example of Java ZonedDateTime class?

Answer: import java.time.ZonedDateTime;  
public class ZonedDateTimeExample1{  
  public static void main(String[] args) {  
    ZonedDateTime zone = ZonedDateTime.parse("2016-10-05T08:20:10+05:30[Asia/Kolkata]");  
    System.out.println(zone);  
  }  
}  

Output:
2016-10-05T08:20:10+05:30[Asia/Kolkata]
Question: What is Java ZoneId Class?


Answer: Java ZoneId class specifies a time zone identifier and provides a rule for converting between an Instant and a LocalDateTime. It inherits Object class and implements the Serializable interface.

There are two sorts of ID:

Fixed offsets are fully resolved offsets from UTC/Greenwich that apply to all local date-times.
Geographical regions are areas where a set of rules for determining the offset from UTC/Greenwich apply.
Question: What is the class declaration for Java Zoneld Class?

Answer: Let's see the declaration of java.time.ZoneId class.

public abstract class ZoneId extends Object implements Serializable  
To allow for the use of short time-zone names, a zone map overrides are employed. In java.util.TimeZone, the usage of short zone IDs is discouraged. The IDs can still be utilised using the of(String, Map) factory function thanks to the map. The map contains a mapping of the IDs that is compatible with TZDB 2005r and later, where 'EST,' 'MST,' and 'HST' correspond to IDs that do not include daylight savings time.
Question: What are the Methods of Java ZoneId Class?

Answer: Methods of Java ZoneId Class

Method:	String getDisplayName(TextStyle style, Locale locale)	
Description: It s used to get the textual representation of the zone, such as 'India Time' or '+05:30'.

Method:	abstract String getId()	
Description: It is used to get the unique time-zone ID.

Method:	static ZoneId of(String zoneId)	
Description: It is used to obtain an instance of ZoneId from an ID ensuring that the ID is valid and available for use.

Method:	static ZoneId systemDefault()	
Description: It is used to get the system default time-zone.

Method:	boolean equals(Object obj)	
Description: It is used to check if this time-zone ID is equal to another time-zone ID.

Method:	static ZoneId from(TemporalAccessor temporal)	
Description: It obtains an instance of ZoneId from a temporal object.

Method:	static Set getAvailableZoneIds()	
Description: It gets the set of available zone IDs.

Method:	abstract ZoneRules getRules()	
Description: It gets the time-zone rules for this ID allowing calculations to be performed.

Method:	int hashCode()	
Description: It returns a hash code for this time-zone ID.

Method:	ZoneId normalized()	
Description: It normalizes the time-zone ID, returning a ZoneOffset where possible.

Method:	static ZoneId of(String zoneId, Map aliasMap)	
Description: It obtains an instance of ZoneId using its ID using a map of aliases to supplement the standard zone IDs.

Method:	static ZoneId ofOffset(String prefix, ZoneOffset offset)	
Description: It obtains an instance of ZoneId wrapping an offset.

Method:	String toString()	
Description: It outputs this zone as a String, using the ID.
Question: Can you provide an example of Java Zoneld Class?

Answer: ZoneIdExample1.java

import java.time.*;  
public class ZoneIdExample1 {  
  public static void main(String... args) {  
    ZoneId zoneid1 = ZoneId.of("Asia/Kolkata");  
    ZoneId zoneid2 = ZoneId.of("Asia/Tokyo");  
    LocalTime id1 = LocalTime.now(zoneid1);  
    LocalTime id2 = LocalTime.now(zoneid2);  
    System.out.println(id1);  
    System.out.println(id2);  
    System.out.println(id1.isBefore(id2));    
  }  
}  

Output:
14:28:58.230
17:58:58.230
true
Question: What is Java ZoneOffset class?

Answer: Java ZoneOffset class
Java ZoneOffset class is used to represent the fixed zone offset from UTC time zone. It inherits the ZoneId class and implements the Comparable interface.

The ZoneOffset class declares three constants:
MAX: It is the maximum supported zone offsets.
MIN: It is the minimum supported zone offsets.
UTC: It is the time zone offset constant for UTC.
Question: What is the class declaration for Java ZoneOffset?

Answer: public final class ZoneOffset extends ZoneId   
implements TemporalAccessor, TemporalAdjuster, Comparable<ZoneOffset>, Serializable
Question: What are the Methods of Java ZoneOffset ?

Answer: Method: Temporal adjustInto(Temporal temporal)
Description: It is used to adjust the specified temporal object to have the same offset as this object.
Method: int get(TemporalField field)
Description: It is used to get the value of the specified field from this offset as an int.
Method: boolean isSupported(TemporalField field)
Description: It is used to check if the specified field is supported.
Method: static ZoneOffset of(String offsetId)
Description: It is used to obtain an instance of ZoneOffset using the ID.
Method: static ZoneOffset ofHours(int hours)
Description: It is used to obtain an instance of ZoneOffset using an offset in hours.
Method: static ZoneOffset ofHoursMinutes(int hours, int minutes)
Description: It is used to obtain an instance of ZoneOffset using an offset in hours and minutes.
Method: ValueRange range(TemporalField field)
Description: It is used to get the range of valid values
Question: Can you provide an example of Java ZoneOffset?

Answer: import java.time.*;  
import java.time.temporal.Temporal;  
public class ZoneOffsetExample1 {  
  public static void main(String[] args) {  
    ZoneOffset zone = ZoneOffset.UTC;  
    Temporal temp = zone.adjustInto(ZonedDateTime.now());  
    System.out.println(temp);  
  }  
}  
Output: 2017-01-29T12:43:00.702+05:30[Asia/Calcutta]
Question: Can you provide an example of Java ZoneOffset: ofHours()?

Answer: import java.time.ZoneOffset;  
public class ZoneOffsetExample2 {  
  public static void main(String[] args) {  
    ZoneOffset zone = ZoneOffset.ofHours(5);  
    System.out.println(zone);  
  }  
}  
Output: +05:00
Question: Can you provide an example of Java ZoneOffset: ofHoursMinutes()?

Answer: import java.time.ZoneOffset;  
public class ZoneOffsetExample3 {  
  public static void main(String[] args) {  
    ZoneOffset zone = ZoneOffset.ofHoursMinutes(5,30);  
    System.out.println(zone);  
  }  
}  
Output: +05:30
Question: Can you provide an example of Java ZoneOffset: isSupported()?

Answer: import java.time.ZoneOffset;  
import java.time.temporal.ChronoField;  
public class ZoneOffsetExample4 {  
  public static void main(String[] args) {  
    ZoneOffset zone = ZoneOffset.UTC;  
    boolean b1 = zone.isSupported(ChronoField.OFFSET_SECONDS);  
    System.out.println(b1);  
    boolean b2 = zone.isSupported(ChronoField.SECOND_OF_MINUTE);  
    System.out.println(b2);  
  }  
}  
Output: true
             false
Question: What is Java Year class?

Answer: Java Year class is an immutable date-time object that represents a year. It inherits the Object class and implements the Comparable interface.
Question: What is the class declaration for Java Year class?

Answer: public final class Year extends Object implements Temporal, TemporalAdjuster, Comparable<Year>, Serializable
Question: What are the Methods of Java Year?

Answer: Method: LocalDate atDay(int dayOfYear)
Description: It is used to combine this year with a day-of-year to create a LocalDate.

Method: String format(DateTimeFormatter formatter)
Description: It is used to format this year using the specified formatter.

Method: int get(TemporalField field)
Description: It is used to get the value of the specified field from this year as an int.

Method: boolean isAfter(Year other)
Description: It is used to check if this year is after the specified year.

Method: boolean isBefore(Year other)
Description: It is used to check if this year is before the specified year.

Method: boolean isLeap()
Description: It is used to check if the year is a leap year, according to the ISO proleptic calendar system rules.

Method: int length()
Description: It is used to get the length of this year in days.

Method: static Year now()
Description: It is used to obtain the current year from the system clock in the default time-zone.
Question: Can you provide an example of Java Year: now()?

Answer: import java.time.Year;  
public class YearExample1 {  
  public static void main(String[] args) {  
    Year y = Year.now();  
    System.out.println(y);  
  }  
}  
Output: 2017
Question: Can you provide an example of Java Year: atDay()?

Answer: import java.time.LocalDate;  
import java.time.Year;  
public class YearExample2{  
  public static void main(String[] args) {  
    Year y = Year.of(2017);  
    LocalDate l = y.atDay(123);  
    System.out.println(l);  
  }  
}  
Output: 2017-05-03
Question: Can you provide an example of Java Year: length()?

Answer: import java.time.Year;  
public class YearExample3 {  
  public static void main(String[] args) {  
    Year year = Year.of(2017);  
    System.out.println(year.length());  
  }  
}  
Output: 365
Question: Can you provide an example of Java Year: isLeap()?

Answer: import java.time.Year;  
public class YearExample4 {  
  public static void main(String[] args) {  
    Year year = Year.of(2016);  
    System.out.println(year.isLeap());  
  }  
}  
Output: true
Question: What is Java YearMonth class?

Answer: Java YearMonth class is an immutable date-time object that represents the combination of a year and month. It inherits the Object class and implements the Comparable interface.
Question: What is the class declaration for Java YearMonth class?

Answer: public final class YearMonth extends Object   
implements Temporal, TemporalAdjuster, Comparable<YearMonth>, Serializable
Question: What are the Methods of Java YearMonth?

Answer: Method: Temporal adjustInto(Temporal temporal)
Description: It is used to adjust the specified temporal object to have this year-month.

Method: String format(DateTimeFormatter formatter)
Description: It is used to format this year-month using the specified formatter.

Method: int get(TemporalField field)
Description: It is used to get the value of the specified field from this year-month as an int.

Method: boolean isLeapYear()
Description: It is used to check if the year is a leap year, according to the ISO proleptic calendar system rules.

Method: static YearMonth now()
Description: It is used to obtain the current year-month from the system clock in the default time zone.

Method: static YearMonth of(int year, int month)
Description: It is used to obtain an instance of YearMonth from a year and month.

Method: YearMonth plus(TemporalAmount amountToAdd)
Description: It is used to return a copy of this year-month with the specified amount added.

Method: YearMonth minus (TemporalAmount amountToSubtract)
Description: It is used to return a copy of this year-month with the specified amount subtracted.

Method: LocalDate atEndOfMonth()
Description: It returns a LocalDate at the end of the month.

Method: int compareTo(YearMonth other)
Description: It compares this year-month to another year-month.

Method: boolean equals(Object obj)
Description: It checks if this year-month is equal to another year-month.

Method: static YearMonth now(Clock clock)
Description: It obtains the current year-month from the specified clock.

Method: static YearMonth of(int year, int month)
Description: It obtains an instance of YearMonth from a year and month.

Method: long until(Temporal endExclusive, TemporalUnit unit)
Description: It calculates the amount of time until another year-month in terms of the specified unit.

Method: YearMonth withMonth(int month)
Description: It returns a copy of this YearMonth with the month-of-year altered.

Method: YearMonth withYear(int year)
Description: It returns a copy of this YearMonth with the year altered.
Question: Can you provide an example of Java YearMonth: now()?

Answer: import java.time.YearMonth;  
public class YearMonthExample1 {  
public static void main(String[] args) {  
  YearMonth ym = YearMonth.now();  
  System.out.println(ym);  
}  
}  
Output: 2017-01
Question: Can you provide an example of Java YearMonth: format()?

Answer: import java.time.YearMonth;  
import java.time.format.DateTimeFormatter;  
public class YearMonthExample2 {  
  public static void main(String[] args) {  
    YearMonth ym = YearMonth.now();  
    String s = ym.format(DateTimeFormatter.ofPattern("MM yyyy"));  
    System.out.println(s);  
  }  
}  
Output: 01 2017