Date Format Example


import java.util.*;
import java.text.*;
class DateFormatDemo
{
public static void main(String A[])
{
//String dob="23/12/1998";
//String dob="DEC/23/1998";
String dob="1998-23-12";
//SimpleDateFormat sdf=new SimpleDateFormat("yyyy'/'dd'/'MM");
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
// Date d=null;
try{

Date d=sdf.parse(dob);//01/31/98
System.out.println("Formated Date="+d);
System.out.println("Formated Date="+sdf.format(d));
}
catch(ParseException pe)
{
System.out.println("Parse Exception Is"+pe);
}

}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s