Java Clock class

The java.time.Clock class providing access to the current instant, date and time using a time-zone. Java Clock class methods Method Description abstract ZoneId getZone() It is used to get the time-zone being used to create dates and times. abstract Instant instant() It is used to get the current instant of the clock. static Clock offset(Clock … Read more

Java 8 OffsetDateTime class

The java.util.OffsetDateTime class is an immutable representation of a date-time with an offset. Java OffsetDateTime class methods Method Description int get(TemporalField field) It is used to get the value of the specified field from this date-time as an int. int getDayOfMonth() It is used to get the day-of-month field. iint getDayOfYear() It is used to … Read more

Java 8 OffsetTime class

The java.time.OffsetTime class is an immutable date-time object that represents a time, often viewed as hour-minute-second offset. Java OffsetTime class methods Method Description String format(DateTimeFormatter formatter) It is used to format this time using the specified formatter. int get(TemporalField field) It is used to get the value of the specified field from this time as … Read more

Java 8 MonthDay class

The java.time.MonthDay is an immutable date-time class that represents the combination of a month and day-of-month. Any field that can be derived from a month and day, such as quarter-of-year, can be obtained. Java MonthDay class methods Method Description LocalDate atYear(int year) It is used to combine this month-day with a year to create a … Read more

Java 8 LocalDateTime class

The java.time.LocalDateTime class is an immutable date-time class that represents a date-time with the default format as yyyy-MM-dd-HH-mm-ss.zzz. This class does not store or represent a time-zone. Instead, it is a description of the date, as used for birthdays, combined with the local time as seen on a wall clock. It cannot represent an instant … Read more

Java 8 LocalTime class

The java.time.LocalTime class is an immutable class that represents a time, often viewed as hour-minute-second. Time is represented to nanosecond precision. For example, the value “13:45.30.123456789” can be stored in a LocalTime. This class does not store or represent a date or time-zone. Instead, it is a description of the local time as seen on … Read more

Java 8 LocalDate class

The java.time.LocalDate class is an immutable class without a time-zone in the ISO-8601 calendar system, such as 2018-04-03. Java LocalDate class methods Method Description LocalDateTime atTime(int hour, int minute) It is used to combine this date with a time to create a LocalDateTime. int compareTo(ChronoLocalDate other) It is used to compares this date to another … Read more

Java 8 Date Time API

Before starting Java date time API, let’s discuss some important drawbacks of old date time API. Some drawbacks of old java date time api All the Date classes in old java date time api are mutable that’s why they are not thread safe. Old java date time classes are not defined consistently. Date Class is … Read more

java date time api

Java date time api provides the classes to represent and manipulate the dates. Classes to represent and manipulate dates are contained in java.time, java.util, java.sql and java.text packages. Java date time api tutorial: java util date class java.text.DateFormat class java text SimpleDateFormat class Java util calendar class Java util GregorianCalendar class java util timezone class … Read more

Java add days to current date

Java add days to current date example package com.w3spoint;   import java.util.Calendar;   public class CalenderTest { public static void main(String args[]){ Calendar calendar = Calendar.getInstance(); System.out.println("The current date is : " + calendar.getTime()); calendar.add(Calendar.DATE, 10); System.out.println("10 days later: " + calendar.getTime()); calendar.add(Calendar.MONTH, 3); System.out.println("3 months later: " + calendar.getTime()); calendar.add(Calendar.YEAR, 4); System.out.println("4 years later: … Read more