ZoneOffset of(String offsetId) example

Description

ZoneOffset of(String offsetId) creates an instance of ZoneOffset using the ID.

The parsing accepts all the formats generated by getId(), plus some additional formats:


Z - for UTC //www .  j  av a 2s.  c  o m
+h 
+hh 
+hh:mm 
-hh:mm 
+hhmm 
-hhmm 
+hh:mm:ss 
-hh:mm:ss 
+hhmmss 
-hhmmss

The maximum supported range is from +18:00 to -18:00 inclusive.

Syntax

of has the following syntax.


public static ZoneOffset of(String offsetId)

Example

The following example shows how to use of.


import java.time.ZoneOffset;
/*www .  java2s .  c o m*/
//ZoneOffset is the period of time representing 
//a difference between Greenwich/UTC and a time zone.

public class Main {
  public static void main(String[] args) {
    ZoneOffset offset = ZoneOffset.of("+2:00");
    System.out.println(offset);
  }
}




















Home »
  Java Date Time »
    java.time Reference »




Clock
DayOfWeek
Duration
Instant
LocalDate
LocalDateTime
LocalTime
Month
MonthDay
OffsetDateTime
OffsetTime
Period
Year
YearMonth
ZonedDateTime
ZoneId
ZoneOffset