Java SimpleDateFormat parse String like "28/10/1965" to Date

Description

Java SimpleDateFormat parse String like "28/10/1965" to Date


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Main {
    public static void main(String[] args) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
        Date dt1 = sdf.parse("28/10/1921");
        Date dt2 = sdf.parse("15/11/2020");
        Date dt3 = sdf.parse("31/12/1998");
        System.out.println(dt1);/*from  www.jav  a2s. c  o m*/
        System.out.println(dt2);
        System.out.println(dt3);
    }
}



PreviousNext

Related