- java.time Package Classes
- java.time - Home
- java.time - Clock
- java.time - Duration
- java.time - Instant
- java.time - LocalDate
- java.time - LocalDateTime
- java.time - LocalTime
- java.time - MonthDay
- java.time - OffsetDateTime
- java.time - OffsetTime
- java.time - Period
- java.time - Year
- java.time - YearMonth
- java.time - ZonedDateTime
- java.time - ZoneId
- java.time - ZoneOffset
- java.time Package Enums
- java.time - Month
- java.time Useful Resources
- java.time - Discussion
java.time.OffsetDateTime.get() Method Example
Description
The java.time.OffsetDateTime.get(TemporalField field) method gets the value of the specified field from this date as an int.
Declaration
Following is the declaration for java.time.OffsetDateTime.get(TemporalField field) method.
public int get(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 int
ArithmeticException − if numeric overflow occurs
Example
The following example shows the usage of java.time.OffsetDateTime.get(TemporalField field) method.
package com.tutorialspoint; import java.time.OffsetDateTime; import java.time.temporal.ChronoField; public class OffsetDateTimeDemo { public static void main(String[] args) { OffsetDateTime date = OffsetDateTime.parse("2017-02-03T12:30:30+01:00"); System.out.println(date.get(ChronoField.CLOCK_HOUR_OF_DAY)); } }
Let us compile and run the above program, this will produce the following result −
12
Advertisements