• Java 8 providing java java.time package which is having more utility methods related to date and time.
  • LocalDateTime class providing plusMinutes(int minutes) method to add minutes to current date or given date in java.
  • Lets see an example program to add 30 minutes to current date using java 8 LocalDateTime class.



#1: Java Example program to add 30 minutes to current date 

  1. package com.instanceofjava.java8;

  2. import java.time.LocalDateTime;

  3. /**
  4.  * @author www.Instanceofjava.com
  5.  * @category interview programs
  6.  * 
  7.  * Description: Add minutes to current date using java 8
  8.  *
  9.  */
  10. public class AddMinutesToDate {

  11. public static void main(String[] args) {
  12. //create data using java 8 LocalDateTime 
  13.     LocalDateTime datetime= LocalDateTime.now();
  14. System.out.println("Before adding minutes to date: "+datetime);
  15.     //add seconds by using plusMinutes(Minutes) method
  16. datetime=datetime.plusMinutes(30);
  17. System.out.println("After adding 30 minutes to date: "+datetime);

  18. }

  19. }



Output:


  1. Before adding minutes to date: 2018-02-05T22:14:33.664
  2. After adding 30 minutes to date: 2018-02-05T22:44:33.664



add minutes to current date java 8


Instance Of Java

We will help you in learning.Please leave your comments and suggestions in comment section. if you any doubts please use search box provided right side. Search there for answers thank you.
«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply

Select Menu