

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Date Parsing using SimpleDateFormat
The SimpleDateFormat class has parse() method, which tries to parse a string according to the format stored in the given SimpleDateFormat object.
Example
import java.util.*; import java.text.*; public class DateDemo { public static void main(String args[]) { SimpleDateFormat ft = new SimpleDateFormat ("yyyy-MM-dd"); String input = args.length == 0 ? "1818-11-11" : args[0]; System.out.print(input + " Parses as "); Date t; try { t = ft.parse(input); System.out.println(t); } catch (ParseException e) { System.out.println("Unparseable using " + ft); } } }
A sample run of the above program would produce the following result −
Output
1818-11-11 Parses as Wed Nov 11 00:00:00 EST 1818
- Related Questions & Answers
- Date Formatting Using SimpleDateFormat
- How to Format a Date String using SimpleDateFormat in Java?
- Java Program to format date with SimpleDateFormat
- Set Date patterns with SimpleDateFormat in Java
- Display today’s date in Java with SimpleDateFormat
- Format date with SimpleDateFormat('MM/dd/yy') in Java
- Formatting day of week using SimpleDateFormat in Java
- How to format year using SimpleDateFormat in Java?
- Fast XML parsing using Expat in Python
- Difference between Top down parsing and Bottom up parsing
- How to use the SimpleDateFormat class to convert a Java Date to a formatted String?
- What is SimpleDateFormat in Java?
- XML parsing in Python?
- Argument Parsing in Python
- Number Parsing in Golang
Advertisements