Wednesday, 14 February 2018

How to add hour, min, Sec to the time using plus methods of OffsetTime Class


Click here to watch on Youtube : 
https://www.youtube.com/watch?v=iRLfu2FZcNI&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.plusHours(1);
        System.out.println("Hour changed          = " + offsetTime2);

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

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

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

    }

}

Output

offsetTime1           = 09:52:52.892+05:30
Hour changed          = 10:52:52.892+05:30
Min changed           = 11:02:52.892+05:30
Sec changed           = 11:03:12.892+05:30
NanoSec changed       = 11:03:12.892000050+05:30

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

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

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