Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Parse string date value input in Java
UseSimpleDateFormat('dd-MMM-yy') for string date.
Format dateFormatter = new SimpleDateFormat("dd-MMM-yy");
For above class, do not forget to import the following package, else an error would be visible.
import java.text.SimpleDateFormat;
Now, parse the date.
Date dt = (Date) dateFormatter.parseObject("20-Nov-18");
Example
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Main {
public static void main(String[] argv) throws Exception {
Format dateFormatter = new SimpleDateFormat("dd-MMM-yy");
// parse
Date dt = (Date) dateFormatter.parseObject("20-Nov-18");
System.out.println("Date = "+dt);
}
}
Output
Date = Tue Nov 20 00:00:00 UTC 2018
Advertisements