Monday, 19 February 2018

How to subtract hour from time using minus method which accepts temporal amount of OffsetTime Class


Click here to watch on Youtube : 
https://www.youtube.com/watch?v=RHHu4tPQcTM&list=UUhwKlOVR041tngjerWxVccw

OffsetTimeDemo.java

import java.time.Duration;
import java.time.OffsetTime;

public class OffsetTimeDemo
{

    public static void main(String[] args)
    {
        OffsetTime offsetTime1 = OffsetTime.now();
        System.out.println("offsetTime1           = " + offsetTime1);
       
        Duration duration = Duration.ofHours(2);
        System.out.println("duration = "+duration);

        /*
         * Parameters:
         *
         * amountToSubtract - the amount to subtract, not null
         *
         * Returns:
         *
         * an OffsetTime based on this time with the subtraction made,
         * not null
         */

        OffsetTime offsetTime2 = offsetTime1.minus(duration);
        System.out.println("offsetTime2           = " + offsetTime2);
    }

}

Output

offsetTime1           = 10:08:03.779+05:30
duration = PT2H
offsetTime2           = 08:08:03.779+05:30

Click the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/OffsetTimeDemo_minus_temporalAmount.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/OffsetTimeDemo_minus_temporalAmount

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/6f1f0d2759f060503c7b9e4a4259ae3ddbfe139e/BasicJava/OffsetTimeDemo_minus_temporalAmount/?at=master

See also:
  • All JavaEE Videos Playlist
  • All JavaEE Videos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • No comments:

    Post a Comment