Wednesday 16 January 2019

How to convert string date to Date using java.text.SimpleDateFormat class


Click here to watch on Youtube: 
https://www.youtube.com/watch?v=Ojyytck09v0&list=UUhwKlOVR041tngjerWxVccw

SimpleDateFormatDemo.java

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class SimpleDateFormatDemo
{
    public static void main(String[] args)
    {
        try
        {
            SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");

            /*
             * Parameters:
             *
             * source - A String whose beginning should be parsed.
             *
             * Returns:
             *
             * A Date parsed from the string.
             */

            Date date = formatter.parse("31/03/2015");
            System.out.println("date = " + date);
        }
        catch (ParseException e)
        {
            e.printStackTrace();
        }

    }

}

Output:

date = Tue Mar 31 00:00:00 IST 2015

Click the below link to download the code:
https://sites.google.com/site/javaspringram2019/java_spring_2019/SimpleDateFormatDemo_Parse.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java_Spring_2019/tree/master/Java_2019/SimpleDateFormatDemo_Parse

Bitbucket Link:
https://bitbucket.org/ramram43210/java_spring_2019/src/4327965661b34e0cc17880946800be5f5d73f2dd/Java_2019/SimpleDateFormatDemo_Parse/?at=master

See also:
  • All JavaEE Videos Playlist
  • All JavaEE Videos
  • All JAVA EE Links
  • Spring Tutorial
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • Cooking Tutorial
  • No comments:

    Post a Comment