GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||
GeezerVison is showing www.geeksforgeeks.org — java.time.OffsetTime Class in Java - GeeksforGeeks java.time.OffsetTime Class in JavaLast Updated : 9 Sep, 2026 The OffsetTime class in Java represents a time with a fixed offset from UTC/Greenwich, such as 18:30:45+08:00. It belongs to the java.time package and stores time values with nanosecond precision.
Example: Program to create an OffsetTime object with a specific time and UTC offset:
Output 18:30:45+08:00 Explanation: The of() method creates an OffsetTime using the hour, minute, second, nanosecond, and UTC offset. Syntax
Creating OffsetTimeJava provides different methods for creating an OffsetTime object. The most commonly used methods are now() and of(). 1. Using now() MethodThe now() method obtains the current time from the system clock. The returned OffsetTime object includes the time and the system's offset.
Output 9 579 34769 Explanation: The program creates an OffsetTime object using now(). It then uses ChronoField with get() to retrieve the hour, minute, and second-related fields. 2. Using getHour(), getMinute(), getSecond() and getNano() MethodsThe getHour(), getMinute(), getSecond(), and getNano() methods retrieve individual components of an OffsetTime object. These methods return the corresponding time field directly.
Output 9 hours 41 minutes 12 seconds 834486561 nanoseconds Explanation: The program obtains the current OffsetTime and retrieves its hour, minute, second, and nanosecond components. The exact output varies according to the system clock. Using of()The of() method creates an OffsetTime from a LocalTime and a ZoneOffset. It is useful when a specific time needs to be associated with a particular UTC offset.
Output 09:42:52.036487319Z Explanation: The program obtains the current LocalTime and combines it with ZoneOffset.UTC. The resulting OffsetTime displays the local time together with the UTC offset. Commonly Used Methods of OffsetTime
Comment Explore | ||||||||||||||||||||||||||||||||||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |