In order to convert a String to Java Date Object, we can make use of the SimpleDateFormat, let us see some examples,
Example 1: Convert 2022-08-26 to Java Date
public static void main(String[] args) throws ParseException {
String dateStr = "2022-08-26";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date date = simpleDateFormat.parse(dateStr);
System.out.println(date);
}
Output:
Fri Aug 26 00:00:00 CST 2022
Note if you do not provide the correct format, you will get an ParseException. Make sure you know what is the date and month fields, if you have a date like 2022-01-02 its hard to say which is month and which is a year unless you have complete information!
Example:Exception in thread "main" java.text.ParseException: Unparseable date: "202208-26"
at java.text.DateFormat.parse(DateFormat.java:366)
at com.example.demo.JavaStreamFiltersExamples.main(JavaStreamFiltersExamples.java:18)
✏️ You can follow this page to see a comprehensive list of all Date formats: List of Simple Date Formats

- Create a Zip file using Java Code programmatically
- Eclipse : A java Runtime Environment (JRE) or Java Development kit (JDK) must be available
- How to Sort a LinkedList in Java
- Loading class com.mysql.jdbc.Driver. This is deprecated. The new driver class is com.mysql.cj.jdbc.Driver
- How to declare and initialize Array in Java Programming
- [Fix] java: integer number too large compilation error
- Java JDBC Connection with MySQL Driver in VS Code + Troubleshooting
- Reading .xls and .xlsx Excel file using Apache POI Java Library
- IntelliJ: Error: Could not find or load main class, java.lang.ClassNotFoundException
- How to get Client IP address using Java Code Example
- Truncate table using Java JDBC Example
- Struts 2 : There is no Action mapped for namespace [/] and action name [form] associated with context path [/proj]
- How to get file path in Idea IntelliJ IDE
- Java Generics explained with simple definition and examples
- Java SE 8 Update 301 available with various bug fixes and security improvements
- Java: Collect Stream as ArrayList or LinkedList
- Java JDBC Connection with PostgreSQL Driver Example
- How to check if Java main thread is alive
- How to fix Java nio NoSuchFileException wile reading a file
- Java 8+ get Day of the Week Examples with LocalDateTime, DateTime, ZonalDateTime and Instant classes
- Ways to Convert Integer or int to Long in Java
- [Java] How to throws Exception using Functional Interface and Lambda code
- [Fix] Spring Boot: mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
- Java: The value of the local variable string is not used
- Java JDBC: Insert Java 8 LocalDate and Time using PreparedStatement
- How to Display content of a file in Terminal Screen? - Linux
- [FIX] AndroidRuntime: FATAL EXCEPTION: main - java.lang.RuntimeException NullPointerException - Android
- Read Java JDBC Connection Details from Properties File - Java
- How to turn off AirPods Nearyby notifications on macOS Big Sur? - Apple
- How to Install CVS Version Control on Linux/Ubuntu - Linux
- How to check your IP using bash for Windows? - Bash
- How to remove or uninstall Java from Ubuntu using apt-get - Linux
- Angular CLI ng Error: You need to specify a command before moving on. Use --help to view the available commands - HowTos