logo

Parses a String value to Date value with given format yyyy-MM-dd HH:mm:ss

Java Code Examples for java.text.SimpleDateFormat.parse()

Parses a String value to Date value with given format yyyy-MM-dd HH:mm:ss.

package simplesolution.dev;

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

public class SimpleDateFormatParseExamples {

    public static void main(String... args) {
        try {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String source = "2019-04-15 10:15:30";
            Date date = simpleDateFormat.parse(source);

            System.out.println(date);
        } catch (ParseException ex) {
            ex.printStackTrace();
        }
    }
}

Happy Coding 😊