Wednesday 14 February 2018

How to subtract hour, min, Sec from time using minus methods of OffsetTime Class


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

OffsetTimeDemo.java

import java.time.OffsetTime;

public class OffsetTimeDemo
{

    public static void main(String[] args)
    {

        OffsetTime offsetTime1 = OffsetTime.now();
        System.out.println("offsetTime1     = " + offsetTime1);

        OffsetTime offsetTime2 = offsetTime1.minusHours(1);
        System.out.println("Hour changed    = " + offsetTime2);

        OffsetTime offsetTime3 = offsetTime2.minusMinutes(10);
        System.out.println("Min changed     = " + offsetTime3);

        OffsetTime offsetTime4 = offsetTime3.minusSeconds(20);
        System.out.println("Sec changed     = " + offsetTime4);

        OffsetTime offsetTime5 = offsetTime4.minusNanos(50);
        System.out.println("NanoSec changed = " + offsetTime5);

    }

}

Output

offsetTime1     = 09:40:02.729+05:30
Hour changed    = 08:40:02.729+05:30
Min changed     = 08:30:02.729+05:30
Sec changed     = 08:29:42.729+05:30
NanoSec changed = 08:29:42.728999950+05:30

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

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

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/b457fe74cff2a0c164eab97a4d02e8169811f425/BasicJava/OffsetTimeDemo_minus/?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