java.time.OffsetTime.getLong() Method Example



Description

The java.time.OffsetTime.getLong(TemporalField field) method gets the value of the specified field from this time as an long.

Declaration

Following is the declaration for java.time.OffsetTime.getLong(TemporalField field) method.

public long getLong(TemporalField field)

Parameters

field − the field to get, not null.

Return Value

the value for the field.

Exceptions

  • DateTimeException − if a value for the field cannot be obtained or the value is outside the range of valid values for the field.

  • UnsupportedTemporalTypeException − if the field is not supported or the range of values exceeds an long.

  • ArithmeticException − if numeric overflow occurs

Example

The following example shows the usage of java.time.OffsetTime.getLong(TemporalField field) method.

package com.tutorialspoint;

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

public class OffsetTimeDemo {
   public static void main(String[] args) {
 
      OffsetTime time = OffsetTime.parse("12:30:30+01:00");
      System.out.println(time.getLong(ChronoField.CLOCK_HOUR_OF_DAY));  
   }
}

Let us compile and run the above program, this will produce the following result −

12
Advertisements