Java Program to format LocalDateTime as ISO_WEEK_DATE format


At first, set the date:

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

Now, format the datetime as ISO_WEEK_DATE format:

String str = dateTime.format(DateTimeFormatter.ISO_WEEK_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, 9, 10, 20);
      System.out.println("DateTime = "+dateTime);
      String str = dateTime.format(DateTimeFormatter.ISO_WEEK_DATE);
      System.out.println("Formatted date = "+str);
   }
}

Output

DateTime = 2019-09-09T10:20
Formatted date = 2019-W37-1

Updated on: 30-Jul-2019

113 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements