- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to convert a String to Date
To convert string to date, you can use the parse method.
The following is our date format.
SimpleDateFormat f = new SimpleDateFormat("dd/MM/yyyy");
Let us convert our string value to date. The value in the parentheses is our string .
Date d = f.parse("13/11/2018");
Example
import java.text.SimpleDateFormat; import java.util.Date; public class Demo { public static void main(String[] args) throws Exception { SimpleDateFormat f = new SimpleDateFormat("dd/MM/yyyy"); Date d = f.parse("13/11/2018"); System.out.println("Date: "+f.format(d)); } }
Output
Date: 13/11/2018
Advertisements