Thursday 15 February 2018

How to subtract hour from time using minus method which accepts long and temporal unit of OffsetTime


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

OffsetTimeDemo.java

import java.time.OffsetTime;
import java.time.temporal.ChronoUnit;

public class OffsetTimeDemo
{

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

        /*
         * Parameters:
         *
         * amountToSubtract - the amount of the unit to subtract from
         * the result, may be negative
         *
         * unit - the unit of the amount to subtract, not null
         *
         * Returns:
         *
         * an OffsetTime based on this time with the specified amount
         * subtracted, not null
         */

        OffsetTime offsetTime2 = offsetTime1.minus(2, ChronoUnit.HOURS);
        System.out.println("offsetTime2   = " + offsetTime2);
       
       
        OffsetTime offsetTime3 = offsetTime2.minus(20, ChronoUnit.MINUTES);
        System.out.println("offsetTime3   = " + offsetTime3);
    }

}

Output

offsetTime1   = 09:58:11.901+05:30
offsetTime2   = 07:58:11.901+05:30
offsetTime3   = 07:38:11.901+05:30

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

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/OffsetTimeDemo-minus_temporalunit

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/c335e42c230dd80d8644831eddbf6afc201dde9c/BasicJava/OffsetTimeDemo-minus_temporalunit/?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
  • 1 comment:

    1. Rattan Khatri, known as the SATTA MATKA,
      from the early 1960s to mid-1990s controlled a nationwide illegal KALYAN FIX JODI with international connections which involved several lakh punters and dealt with crores of rupess

      ReplyDelete