Java Date Time - LocalTime format(DateTimeFormatter formatter) example








LocalTime 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.LocalTime;
import java.time.format.DateTimeFormatter;
//from   w  w w . jav a 2s .  com
public class Main {
  public static void main(String[] args) {
    LocalTime l = LocalTime.now();
    String s = l.format(DateTimeFormatter.ISO_LOCAL_TIME);
    System.out.println(s);
  }
}

The code above generates the following result.