LocalDate Java Example
This class has been introduced in JDK 1.8 which can be used without time-zone in the ISO-8601 calendar system and it will fetch local date based on the location.
- LocalDateExample.java:
package com.javahonk.dateformatter; import java.time.LocalDate; import java.time.format.DateTimeFormatter; public class LocalDateExample { public static void main(String[] args) { String validPatterns = "yyyy-MM-dd"; System.out.println("Please be carefull while using LocalDate as It can not format date except yyyyMMdd format\n"); DateTimeFormatter formatter = DateTimeFormatter.ofPattern(validPatterns); System.out.println("yyyy-MM-dd:--> "+LocalDate.now().format(formatter)); System.out.println("BASIC_ISO_DATE:--> "+LocalDate.now().format(DateTimeFormatter.BASIC_ISO_DATE)); System.out.println("ISO_DATE:--> "+LocalDate.now().format(DateTimeFormatter.ISO_DATE)); } }
- Output:
- For more informatoin about this API please visit Oracle documentation here