- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
How to convert String to Date in java?
SimpleDateFormat is a concrete class for formatting and parsing dates in a locale-sensitive manner. SimpleDateFormat allows you to start by choosing any user-defined patterns for date-time formatting.
The SimpleDateFormat class has some additional methods, notably parse( ), which tries to parse a string according to the format stored in the given SimpleDateFormat object.
Example
import java.text.SimpleDateFormat; import java.util.Date; public class DateString { public static void main(String args[]) throws Exception{ String date = "21-9-2017"; SimpleDateFormat sdt = new SimpleDateFormat("dd-MM-YYYY"); Date result = sdt.parse(date); System.out.println(result); } }
Output
Sun Jan 01 00:00:00 IST 2017
- Related Articles
- How to convert Date to String in Java 8?
- Convert String to Date in Java
- Java Program to Convert String to Date
- Java Program to convert a String to Date
- How to Convert Date to String in TypeScript?
- How to convert a string to date in MySQL?
- How to convert a Python date string to a date object?
- How to convert a Date value to string in JDBC?
- How to convert a string in to date object in JavaScript?
- How to use the SimpleDateFormat class to convert a Java Date to a formatted String?
- Convert date string to timestamp in Python
- How to convert from string to date data type in MongoDB?
- How to convert unix timestamp string to readable date in Python?
- How to convert a JavaScript date object to a string?
- How to format a date to String in Java?

Advertisements