How to parse custom formatted date string into Date object in Java

1 Answer

0 votes
package javaapplication1;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class JavaApplication1 {

    public static void main(String[] args) {

        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");

        try {
            Date date = sdf.parse("31/10/2016");
            System.out.println(date);
        } catch (ParseException pe) {
            System.out.println(pe.getMessage());
        }
    }
}
   
/*
   
run:
   
Mon Oct 31 00:00:00 IST 2016
   
*/

 



answered Oct 31, 2016 by avibootz

Related questions

1 answer 152 views
152 views asked Mar 24, 2021 by avibootz
1 answer 177 views
2 answers 251 views
1 answer 156 views
156 views asked Aug 5, 2017 by avibootz
3 answers 308 views
...