Knowledge Walls
John Peter
Pune, Maharashtra, India
Parsing DateTime String to Date Object in Core Java
2437 Views
Hints 
SimpleDateFormat utility class is used to parse and format the Date from string and date object. parse and format methods are used to handle the date information mainly.

SimpleDateFormat is a class of java.text.SimpleDateFormat. Below example explained how to parse and format a date using SimpleDateFormat only with Date informations Month, Day and Year.

Example
new SimpleDateFormat("dd/MM/yyyy").parse("12/12/1998");
DateStringParser
import java.text.SimpleDateFormat;

public class DateStringParser {
    public static void main(String args[]) throws InterruptedException, Exception{
        //Define the input date format with SimpleDateFormat Constructor
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
        
        String inputDate = "29/12/2014";
        System.out.println(sdf.parse(inputDate));
    }
}
Output 
Mon Dec 29 00:00:00 IST 2014
Next
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details