- 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 parse date and time
Create a SimpleDateFormat object −
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss");
Do not forget to import the following package for SimpleDateFormat class −
import java.text.SimpleDateFormat;
Now, since we have set the format for date above, let us parse the date using parseObject() method −
Date dt = (Date) dateFormat.parseObject("2018.11.22.11.50.15");
The following is an example −
Example
import java.util.Date; import java.text.SimpleDateFormat; public class Demo { public static void main(String[] argv) throws Exception { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss"); // parse System.out.println("Parse Date and Time..."); Date dt = (Date) dateFormat.parseObject("2018.11.22.11.50.15"); System.out.println(dt); } }
Output
Parse Date and Time... Thu Nov 22 11:50:15 UTC 2018
- Related Articles
- Parse string date time value input in Java
- Java Program to parse Time using custom format
- Format and Parse Date in Java
- Java Program to parse string date value with default format
- Java Program to Display current Date and Time
- How to parse date sting to date in Java?
- Golang program to parse time
- Java Program to display date and time in Milliseconds
- Java Program to Get Current Date/Time
- Java Program to display date and time information in lowercase
- Java Program to display date and time information in uppercase
- Java Program to format date time with Join
- Parse string date value input in Java
- Java Program to parse a mathematical expression and operators
- Java program to add a given time to a particular date

Advertisements