CodesJava

Easy learning with example program codes

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

Method Description
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.

Example

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

Output

18
1136
68193
Posted in Date   


Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap