LocalDateTime withMinute() method in Java with Examples Last Updated : 30 Nov, 2018 Comments Improve Suggest changes Like Article Like Report The withMinute() method of LocalDateTime class in Java is used to get a copy of this LocalDateTime with the minutes changed to the minutes passed as the parameter to this method. The remaining values of this LocalDateTime remains the same. Syntax: public LocalDateTime withMinute(int minutes) Parameter: This method accepts a single mandatory parameter minutes which specifies the minutes to be set in the resultant LocalDateTime instance. The value of this minutes can range from 0 to 59. Returns: The function returns a LocalDateTime instance with the minutes changed to the minutes passed as the parameter to this method. The remaining values of this LocalDateTime remains the same. Exceptions: The function throws a DateTimeException if the minutes value is invalid. Below programs illustrate the LocalDateTime.withMinute() method: Program 1: Java // Program to illustrate the withMinute() method import java.util.*; import java.time.*; public class GfG { public static void main(String[] args) { // Get the LocalDateTime instance LocalDateTime dt = LocalDateTime.now(); // Get the String representation of this LocalDateTime System.out.println("Original LocalDateTime: " + dt.toString()); // Get a new LocalDateTime with minutes 0 System.out.println("New LocalDateTime: " + dt.withMinute(0)); } } Output: Original LocalDateTime: 2018-11-30T12:52:26.105 New LocalDateTime: 2018-11-30T12:00:26.105 Program 2: Java // Program to illustrate the withMinute() method import java.util.*; import java.time.*; public class GfG { public static void main(String[] args) { // Get the LocalDateTime instance LocalDateTime dt = LocalDateTime .parse("2015-04-06T10:15:30"); // Get the String representation of this LocalDateTime System.out.println("Original LocalDateTime: " + dt.toString()); // Get a new LocalDateTime with minutes 59 System.out.println("New LocalDateTime: " + dt.withMinute(59)); } } Output: Original LocalDateTime: 2015-04-06T10:15:30 New LocalDateTime: 2015-04-06T10:59:30 Reference: https://docs.oracle.com/javase/10/docs/api/java/time/LocalDateTime.html#withMinute(int) Comment More infoAdvertise with us Next Article LocalDateTime with() Method in Java with Examples G gopaldave Follow Improve Article Tags : Java Java-LocalDateTime Java-Functions Java-time package Practice Tags : Java Similar Reads LocalTime withMinute() method in Java with Examples The withMinute() method of a LocalTime class is used to get a copy of this LocalTime with the minutes changed to the minutes passed as the parameter to this method. The remaining values of this LocalTime will remain the same. This instance is immutable and unaffected by this method call. Syntax: pub 2 min read LocalDateTime with() Method in Java with Examples In LocalDateTime class, there are two types of with() method depending upon the parameters passed to it. with(TemporalAdjuster adjuster) with(TemporalAdjuster adjuster) method of the LocalDateTime class used to adjusted this date-time using TemporalAdjuster and after adjustment returns the copy of a 3 min read LocalDateTime withNano() method in Java with Examples withNano() method of LocalDateTime class in Java is used to get a copy of this LocalDateTime with the nano-seconds changed to the nano-seconds passed as the parameter to this method. The remaining values of this LocalDateTime remain the same. Syntax: public LocalDateTime withNano(int nanoSeconds) Pa 3 min read LocalDateTime withNano() method in Java with Examples withNano() method of LocalDateTime class in Java is used to get a copy of this LocalDateTime with the nano-seconds changed to the nano-seconds passed as the parameter to this method. The remaining values of this LocalDateTime remain the same. Syntax: public LocalDateTime withNano(int nanoSeconds) Pa 3 min read LocalDateTime withNano() method in Java with Examples withNano() method of LocalDateTime class in Java is used to get a copy of this LocalDateTime with the nano-seconds changed to the nano-seconds passed as the parameter to this method. The remaining values of this LocalDateTime remain the same. Syntax: public LocalDateTime withNano(int nanoSeconds) Pa 3 min read LocalDateTime withHour() method in Java with Examples The withHour() method of LocalDateTime class in Java is used to get a copy of this LocalDateTime with the hours changed to the hours passed as the parameter to this method. The remaining values of this LocalDateTime remains the same. Syntax: public LocalDateTime withHour(int hours) Parameter: This m 2 min read Like