Period ofDays() method in Java with Examples Last Updated : 28 Nov, 2018 Summarize Comments Improve Suggest changes Share Like Article Like Report The ofDays() method of Period Class is used to obtain a period from given number of Days as parameter. This parameter is accepted in the form of integer. This method returns a Period with the given number of days. Syntax: public static Period ofDays(int numberOfDays) Parameters: This method accepts a single parameter numberOfDays which is the number of Days to be parsed into an Period object. Returns: This function returns the period which is the Period object parsed with the given number of Days. Below is the implementation of Period.ofDays() method: Example 1: Java // Java code to demonstrate ofDays() method import java.time.Period; class GFG { public static void main(String[] args) { // Get the number of Days int numberOfDays = 5; // Parse the numberOfDays into Period // using ofDays() method Period p = Period.ofDays(numberOfDays); System.out.println(p.getYears() + " Years\n" + p.getMonths() + " Months\n" + p.getDays() + " Days"); } } Output: 0 Years 0 Months 5 Days Example 2: Java // Java code to demonstrate ofDays() method import java.time.Period; class GFG { public static void main(String[] args) { // Get the number of Days int numberOfDays = -5; // Parse the numberOfDays into Period // using ofDays() method Period p = Period.ofDays(numberOfDays); System.out.println(p.getYears() + " Years\n" + p.getMonths() + " Months\n" + p.getDays() + " Days"); } } Output: 0 Years 0 Months -5 Days Reference: https://docs.oracle.com/javase/9/docs/api/java/time/Period.html#ofDays-int- Comment More infoAdvertise with us Next Article Period ofWeeks() method in Java with Examples B barykrg Follow Improve Article Tags : Misc Java Java-Functions Java-time package Java-Period +1 More Practice Tags : JavaMisc Similar Reads Period of() method in Java with Examples The of() method of Period Class is used to obtain a period from given number of Years, Months, and Days as parameters. These parameters are accepted in the form of integers. This method returns a Period with the given number of years, months, and days. Syntax: public static Period of( int numberOfYe 2 min read Period ofYears() method in Java with Examples The ofYears(int numberOfYears) method of Period class is used to get a period from the given number of years as parameter. The obtained period will represent the number of years. The unit month and days shall remain 0. Syntax: public static Period ofYears(int numberOfYears) Parameters: This method a 2 min read Period ofWeeks() method in Java with Examples The ofWeeks() method of Period Class is used to obtain a period from given number of Weeks as parameter. This parameter is accepted in the form of integer. This method returns a Period with the given number of weeks. Syntax: public static Period ofWeeks(int numberOfWeeks) Parameters: This method acc 2 min read Period minusDays() method in Java with Examples The minusDays() method of Period class in Java is used to subtract the days from this Period. This functions operates only on DAYS and does not affect YEAR and MONTH. Syntax: public Period minusDays(long daysToSubtract) Parameters: This method accepts a single parameter daysToSubtract which is the n 2 min read Period parse() method in Java with Examples The parse() method of Period Class is used to obtain a period from given string in the form of PnYnMnD where nY means n years, nM means n months and nD means n days. Syntax: public static Period parse(CharSequence text) Parameters: This method accepts a single parameter text which is the String to b 2 min read Period ofMonths() method in Java with Examples The ofMonths() method of Period Class is used to obtain a period from given number of Months as parameter. This parameter is accepted in the form of integer. This method returns a Period with the given number of months. Syntax: public static Period ofMonths(int numberOfMonths) Parameters: This metho 2 min read Like