Monday 19 February 2018

How to use range method OffsetTime Class which accepts temporal field


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

OffsetTimeDemo.java

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

public class OffsetTimeDemo
{

    public static void main(String[] args)
    {

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

        /*
         * Gets the range of valid values for the specified field.
         *
         * Parameters:
         *
         * field - the field to query the range for, not null
         *
         * Returns:
         *
         * the range of valid values for the field, not null
         */

        ValueRange valueRange = offsetTime.range(ChronoField.CLOCK_HOUR_OF_DAY);

        System.out.println("Range = " + valueRange);
        System.out.println("Max   = " + valueRange.getMaximum());
        System.out.println("min   = " + valueRange.getMinimum());
    }

}

Output

offsetTime = 08:19:20.784+05:30
Range = 1 - 24
Max   = 24
min   = 1

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

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

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