loader image Authenticating...

Convert date from one format to another format

by Vinoth 2008-10-14 18:18:30

Hi,
The bellow code will give the solution to format date one form to another form

import java.util.Date;
import java.text.*;

public class Date1
{
public static void main(String args[]) throws Exception{
String strDate = "2008-10-14";
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
Date dateStr = formatter.parse(strDate);
String formattedDate = formatter.format(dateStr);
System.out.println("yyyy-MM-dd date is ==>"+formattedDate);
Date date1 = formatter.parse(formattedDate);

formatter = new SimpleDateFormat("dd-MMM-yyyy");
formattedDate = formatter.format(date1);
System.out.println("dd-MMM-yyyy date is ==>"+formattedDate);
}
}


the output will be


yyyy-MM-dd date is ==> 2008-10-14
dd-MMM-yyyy date is ==> 14-OCT-2008

Tagged in:

10027
like
4
dislike
0
mail
flag

You must LOGIN to add comments