Java 8 OffsetTime class

The java.time.OffsetTime class is an immutable date-time object that represents a time, often viewed as hour-minute-second offset.

Java OffsetTime class methods

String format(DateTimeFormatter formatter)It is used to format this time using the specified formatter.
int get(TemporalField field)It is used to get the value of the specified field from this time as an int.
int getHour()It is used to get the hour-of-day field.
int getMinute()It is used to get the minute-of-hour field.
int getSecond()It is used to get the second-of-minute field.
static OffsetTime now()It is used to obtain the current time from the system clock in the default time-zone.
static OffsetTime of(LocalTime time, ZoneOffset offset)It is used to obtain an instance of OffsetTime from a local time and an offset.
ValueRange range(TemporalField field)It is used to get the range of valid values for the specified field.
VLocalTime toLocalTime()It is used to get the LocalTime part of this date-time.


package com.w3spoint;
import java.time.OffsetTime;
import java.time.temporal.ChronoField;
public class TestExample {
	public static void main(String args[]){
		OffsetTime offset =;  
	    int hour = offset.get(ChronoField.HOUR_OF_DAY);  
	    int minute = offset.get(ChronoField.MINUTE_OF_DAY);  
	    int second = offset.get(ChronoField.SECOND_OF_DAY);  


Content Protection by
Please Share