Wednesday 14 February 2018

How to get hour, minute, sec using get method which accepts temporal field of OffsetTime Class


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

OffsetTimeDemo.java

import java.time.OffsetTime;
import java.time.temporal.ChronoField;

public class OffsetTimeDemo
{

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

        /*
         * Parameters:
         *
         * field - the field to get, not null
         *
         * Returns:
         *
         * the value for the field
         *
         */

        int hour = offsetTime.get(ChronoField.HOUR_OF_DAY);
        System.out.println("hour = " + hour);

        int minute = offsetTime.get(ChronoField.MINUTE_OF_HOUR);
        System.out.println("minute = " + minute);

        int seconds = offsetTime.get(ChronoField.SECOND_OF_MINUTE);
        System.out.println("seconds = " + seconds);
    }

}

Output

offsetTime = 09:58:56.596+05:30
hour = 9
minute = 58
seconds = 56

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

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

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