Java Convert String to Date

Tags: Java Date SimpleDateFormat String

In this Java core tutorial, we learn how to convert a String value into a Date object using the java.text.SimpleDateFormat class in Java programming language.

How to convert String to Date in Java

In Java, with a given date time String in specified date time pattern, we can use the SimpleDateFormat.parse(String source) method to convert it to a Date object as the following example Java code.

ConvertStringToDateExample.java

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

public class ConvertStringToDateExample {
    public static void main(String... args) throws ParseException {
        String dateInString = "2022/08/01 08:30:00";

        // Convert String to Date
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        Date date = simpleDateFormat.parse(dateInString);

        System.out.println(date);
    }
}
The output as below.
Mon Aug 01 08:30:00 ICT 2022

Happy Coding 😊

Java Convert Date to Start of Day Time

Java Convert Date to End of Day Time

Java Get First Date of Current Year

Java Get First Date of Current Month

Java Get Same Date in Last Month

Java Get First Day of Month from Specified Date

Java Get Yesterday Date

Java Get Tomorrow Date

Java Get Last Date of Current Month

Java Get Last Date of Current Year

Java Get Last Date of Specified Month

Java Get Last Date of Specified Year

Java Check if Calendar is Week Day or Weekend Day

Java Check if Date is Week Day or Weekend Day

Java Check if Today is Week Day or Weekend Day