Java Date Time - OffsetTime format(DateTimeFormatter formatter) example








OffsetTime format(DateTimeFormatter formatter) formats this time using the specified formatter.

Syntax

format has the following syntax.

public String format(DateTimeFormatter formatter)

Example

The following example shows how to use format.

import java.time.OffsetTime;
import java.time.format.DateTimeFormatter;
//from w ww  . j  a v a  2s  .c  o  m
public class Main {
  public static void main(String[] args) {
    OffsetTime m = OffsetTime.now();
    String s = m.format(DateTimeFormatter.ISO_OFFSET_TIME);
    System.out.println(s);

  }
}

The code above generates the following result.