Date after() method in Java Last Updated : 07 Nov, 2019 Comments Improve Suggest changes Like Article Like Report The java.util.Date.after() method is used to check whether the current instance of the date is after the specified date. Syntax: dateObject.after(Date specifiedDate) Parameter: It takes only one parameter specifiedDate of data type Date. This is the date which is to be checked in comparison to the instance of the date calling the function. Return Value: The return type of this function is boolean. It returns true if current instance of the date is strictly larger than the specifiedDate. Otherwise it returns false. Exceptions: If the specifiedDate is null, this method will throw NullPointerException when called upon. Below programs illustrate after() method in Date class: Program 1: Java // Java code to demonstrate // after() function of Date class import java.util.Date; import java.util.Calendar; public class GfG { // main method public static void main(String[] args) { // creating a Calendar object Calendar c = Calendar.getInstance(); // set Month // MONTH starts with 0 i.e. ( 0 - Jan) c.set(Calendar.MONTH, 11); // set Date c.set(Calendar.DATE, 05); // set Year c.set(Calendar.YEAR, 1996); // creating a date object with specified time. Date dateOne = c.getTime(); // creating a date of object // storing the current date Date currentDate = new Date(); System.out.print("Is currentDate after date one : "); // if currentDate is after dateOne System.out.println(currentDate.after(dateOne)); } } Output: Is currentDate after date one : true Program 2: To demonstrate java.lang.NullPointerException Java // Java code to demonstrate // after() function of Date class import java.util.Date; public class GfG { // main method public static void main(String[] args) { // creating a date of object // storing the current date Date currentDate = new Date(); // specifiedDate is assigned to null. Date specifiedDate = null; System.out.println("Passing null as parameter : "); try { // throws NullPointerException System.out.println(currentDate.after(specifiedDate)); } catch (Exception e) { System.out.println("Exception: " + e); } } } Output: Passing null as parameter : Exception: java.lang.NullPointerException Comment More infoAdvertise with us Next Article Date after() method in Java S ShivamKD Follow Improve Article Tags : Java Java - util package Java-Functions Java-Date-Time Java-util-Date +1 More Practice Tags : Java Similar Reads Year atDay() method in Java The atDay() method of Year class in Java combines the current year with a day-of-year passed as parameter to it to create a LocalDate. Syntax: public LocalDate atDay(int dayOfYear) Parameter: This method accepts a single parameter dayOfYear. It is the day-of-year to use. It can take values from 1 to 2 min read DateFormat format(Date obj) method in Java The format() method of DateFormat class in Java is used to format a given Date object into a string representing Date/Time.Syntax: String format(Date date) Parameters: This method accepts a single parameter date which is a Date object. Return Value: This method returns a String which is the formatte 2 min read Year atMonthDay() method in Java The atMonthDay(MonthDay) method of Year class in Java combines the current year object with a month-day object passed as parameter to it to create a LocalDate object. Syntax: public LocalDate atMonthDay(MonthDay monthDay) Parameter: This method accepts a single parameter monthDay. It is the MonthDay 2 min read YearMonth atDay() method in Java The atDay() method of YearMonth class in Java combines the current year-month with a day-of-month passed as parameter to it to create a LocalDate. Syntax: public LocalDate atDay(int dayOfMonth) Parameter: This method accepts a single parameter dayOfMonth. It is the day-of-month to use. It can take v 2 min read Date before() method in Java with Examples The before() method of Java Date class tests whether the date is before the specified date or not. Syntax: public boolean before(Date when) Parameters: The function accepts a single parameter when which specifies the date that has to be checked. Return Value: It returns a Boolean value. It will retu 2 min read Like