date to locale string code example

Example 1: date to localdate

dateToConvert.toInstant()
      .atZone(ZoneId.systemDefault())
      .toLocalDate();

Example 2: toLocaleDateString() options

new Date("1983-March-25").toLocaleDateString('fr-CA', { year: 'numeric', month: '2-digit', day: '2-digit' })
'03/25/1983'

Example 3: convert localdatetime to localdate

import java.time.LocalDate;
import java.time.LocalDateTime;
 
public class Main {
    public static void main(String[] args) {
 
        LocalDateTime localDateTime = LocalDateTime.now();
         
        LocalDate localDate = localDateTime.toLocalDate();
         
        System.out.println(localDate);
    }
}

Tags:

Java Example