We would like to know how to format date as '23/06/2015'.
import java.time.LocalDate; import java.time.format.DateTimeFormatter; /* w w w.j a v a2s . co m*/ public class Main { public static void main(String[] args) { System.out.println(toString(LocalDate.now())); } public static String toString(LocalDate date) { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy"); return date.format(formatter); } }
The code above generates the following result.