1024programmer Java ZonedDateTimeplusMinutes() method in Java, example

ZonedDateTimeplusMinutes() method in Java, example

ZonedDateTime plusMinutes() method in Java, examples

Original text: https://www . geeksforgeeks . org/zoneddatetime-plusminutes-method-in-Java-with-examples/

plusMinutes() A method of the ZonedDateTime class, used to add minutes to this ZonedDateTime and return a ZonedDateTime after adding copy. The method operates on the immediate timeline, so adding a minute will always be the duration one minute later. This instance is immutable and is not affected by calls to this method.

Syntax:

public ZonedDateTime plusMinutes(long minutes)

Parameters:This method accepts The single parameter minutes represents the number of minutes to be added and can be a negative number.

Return value: This method returns a regional time based on the date and time plus minutes, which is not empty.

Exception: This method throws a DateTimeException if the result is outside the supported date range.

The following program illustrates the plusMinutes() method:
Program 1:

// Java program to demonstrate
// ZonedDateTime.plusMinutes() method
import java.time.*;
public class GFG {
  public static void main(String[] args)
 {
 // create a ZonedDateTime object
ZonedDateTime zoneddatetime
                                                      ZonedDateTime.parse(
                                                    ="s">"2018-12-06T19:21:12.123+05:30[Asia/Calcutta]");
 // print instance
 System.out .println("ZonedDateTime before"
                                                                                                                               o">+ zoneddatetime);
 // add 3 minutes
ZonedDateTime returnvalue
   = zoneddatetime.plusMinutes(3);
 // print result
 System.out.println("ZonedDateTime after "
                                        class="o">+ " adding minutes: "
                                      ">returnvalue);
 }
}

Output:

Region added time minutes ago: 2018-12-06T19: 21:12.123+05:30【Asia/Kolkata】
Region addition time after adding minutes: 2018-12-06T19:24:12.123+05:30【Asia/Kolkata】

Program 2:

// Java program to demonstrate
// ZonedDateTime.plusMinutes() method
import java.time.*;
public class GFG {
public static void main(String[] args)
 {
 // create a ZonedDateTime object
 ZonedDateTime zoneddatetime
                                                               /span> ZonedDateTime.parse (
 "2018-10-25T23:12:31.123+02:00[Europe/Paris]");
 // print instance
 System.
span>out.println( "ZonedDateTime before"
                                                                                 /span>
 + zoneddatetime);
 // add 20 minutes
 ZonedDateTime returnvalue
 = zoneddatetime.plusMinutes (20);
 // print result
 System.out.println("ZonedDateTime after "
                                                                                                                            + returnvalue);
 }
}

Output:

Add minutes ago The region added time: 2018-10-25T23:12:31.123+02:00【Europe/Paris】
The region added time minutes after adding: 2018-10-25T23:32:31.123+02:00【Europe/ Paris]

Reference:T2 [https://docs . Oracle . com/javase/10/docs/API/Java/time/zoneddatetime . html # plusMinutes(long)

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/zoneddatetimeplusminutes-method-in-java-example/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索