Java Data Type How to - Format LocalTimeDate as BASIC_ISO_DATE format


We would like to know how to format LocalTimeDate as BASIC_ISO_DATE format.


//  w  w  w. j  a  v a 2s  .  c o  m
import java.time.LocalDateTime;
import java.time.Month;
import java.time.format.DateTimeFormatter;

public class Main {
  public static void main(String[] args) {
    // 2014-04-01 10:45
    LocalDateTime dateTime = LocalDateTime.of(2014, Month.APRIL, 1, 10, 45);

    // format as basic ISO date format (20140220)
    String asBasicIsoDate = dateTime.format(DateTimeFormatter.BASIC_ISO_DATE);

The code above generates the following result.