YearMonth now() method in Java with Examples Last Updated : 08 May, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report The now() method of the YearMonth class in Java is used to obtain the current year-month from the system clock in the default time-zone. Syntax: public static YearMonth now() Parameters: This method does not accept any parameter. Return value: This method returns the current year-month using the system clock and default time-zone. Below programs illustrate the now() method of YearMonth in Java: Program 1: Java // Java program to demonstrate // YearMonth.now() method import java.time.*; import java.time.temporal.*; public class GFG { public static void main(String[] args) { // apply now() method // of YearMonth class YearMonth result = YearMonth.now(); // print both year and month System.out.println("YearMonth: " + result); } } Output: YearMonth: 2020-05 Program 2: Java // Java program to demonstrate // YearMonth.now() method import java.time.*; import java.time.temporal.*; public class GFG { public static void main(String[] args) { // apply now() method // of YearMonth class YearMonth result = YearMonth.now(); // print only year System.out.println( "Year: " + result.get(ChronoField.YEAR)); } } Output: Year: 2020 References: https://docs.oracle.com/javase/10/docs/api/java/time/YearMonth.html#now() Comment More infoAdvertise with us Next Article YearMonth get() method in Java with Examples P pp_pankaj Follow Improve Article Tags : Java Java-Functions Java-YearMonth Practice Tags : Java Similar Reads Year now() method in Java with examples The now() method of Year class in Java is used to return the current year from the system clock in the default time-zone. Syntax: public static Year now() or, public static Year now(Clock clock) or, public static Year now(ZoneId zone) Parameter: The parameter is optional for this method as shown in 2 min read YearMonth now(clock) method in Java with Examples now(Clock clock) method of the YearMonth class in Java is used to obtain the current year-month from the specified clock. Syntax: public static YearMonth now(Clock clock) Parameters: This method accepts clock as parameter which represents the clock to use. Return value: This method returns the curre 1 min read YearMonth until() Method in Java with Examples until() method of the YearMonth class used to calculate the amount of time between two YearMonth objects using TemporalUnit. The start and end points are this and the specified YearMonth passed as a parameter. The result will be negative if the end is before the start. The calculation returns a whol 2 min read YearMonth get() method in Java with Examples The get() method of the YearMonth class in Java is used to get the value of the specified field from this year-month as an integer value. This method queries this year-month for the value of the specified field. The returned value will always be within the valid range. An exception is thrown if it i 2 min read YearMonth plusYears() method in Java with Examples The plusYears() method of YearMonth class in Java is used to return a copy of this YearMonth with the specified number of years added. Syntax: public YearMonth plusYears(long yearsToAdd) Parameter: This method accepts yearsToAdd as parameters which represents years to add to current YearMonth object 2 min read Year until() Method in Java with Examples until() method of the Year class used to calculate the amount of time between two Year objects using TemporalUnit. The start and end points are this and the specified Year passed as a parameter. The result will be negative if the end is before the start. The calculation returns a whole number, repre 2 min read Like