Wednesday, 14 February 2018

Java 8 OffsetTime Class Introduction | Java 8 Date and Time | Java Date and Time


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

Click the below Image to Enlarge

Java 8 OffsetTime Class Introduction | Java 8 Date and Time | Java Date and Time
OffsetTimeDemo.java

import java.time.OffsetTime;
import java.time.ZoneOffset;

public class OffsetTimeDemo
{

    public static void main(String[] args)
    {

        /*
         * Returns:
         *
         * the current time using the system clock and default
         * time-zone, not null
         */

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

        int hour = currentTime.getHour();
        System.out.println("hour = " + hour);

        int minute = currentTime.getMinute();
        System.out.println("minute = " + minute);

        int seconds = currentTime.getSecond();
        System.out.println("seconds = " + seconds);

        int nanoSeconds = currentTime.getNano();
        System.out.println("nanoSeconds = " + nanoSeconds);

        ZoneOffset zoneOffset = currentTime.getOffset();
        System.out.println("zoneOffset = " + zoneOffset.getId());
    }

}

Output

currentTime = 09:55:12.169+05:30
hour = 9
minute = 55
seconds = 12
nanoSeconds = 169000000
zoneOffset = +05:30

Refer:
https://docs.oracle.com/javase/8/docs/api/index.html?java/time/OffsetTime.html

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

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

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