Java Program to format LocalTimeDate as BASIC_ISO_DATE format


At first, set the date:

LocalDateTime dateTime = LocalDateTime.of(2019, Month.SEPTEMBER, 6, 20, 10);

Now, format the datetime as BASIC_ISO_DATE format:

String str = dateTime.format(DateTimeFormatter.BASIC_ISO_DATE);

Example

import java.time.LocalDateTime;
import java.time.Month;
import java.time.format.DateTimeFormatter;
public class Demo {
   public static void main(String[] args) {
      LocalDateTime dateTime = LocalDateTime.of(2019, Month.SEPTEMBER, 6, 20, 10);
      System.out.println("DateTime = "+dateTime);
      String str = dateTime.format(DateTimeFormatter.BASIC_ISO_DATE);
      System.out.println("Formatted date = "+str);
   }
}

Output

DateTime = 2019-09-06T20:10
Formatted date = 20190906

Updated on: 30-Jul-2019

264 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements