Display ISO 8601 standard date in Java

Java 8Object Oriented ProgrammingProgramming

Use the ‘F’ date conversion character to display ISO 8601 standard date.

System.out.printf("ISO 8601 standard date = %tF\n", d);

Above, d is a date object.

Date d = new Date();

Example

 Live Demo

import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
public class Demo {
   public static void main(String[] args) throws Exception {
      Date d = new Date();
      System.out.printf("Four-digit Year = %TY\n",d);
      System.out.printf("Two-digit Year = %ty\n",d);
      System.out.printf("ISO 8601 standard date = %tF\n", d);
   }
}

Output

Four-digit Year = 2018
Two-digit Year = 18
ISO 8601 standard date = 2018-11-26
raja
Published on 14-Dec-2018 05:54:07
Advertisements