on 06-05-2007 4:31 AM
All,
I have a string with value say 20061030, I want to convert the value into 10/30/2006 (MM/DD/YYYY)
How can I do that.
Thanks...
BM
Hi Bharathi,
You can try this code...
//Convert String to Date object
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateFormatTest
{
public static void main ( String [ ] cmdArgs )
throws Exception
{
SimpleDateFormat sdfInput =
new SimpleDateFormat ( "yyyy-MM-dd" ) ;
SimpleDateFormat sdfOutput =
new SimpleDateFormat ( "MM/dd/yyyy" ) ;
String textDate = "2001-01-04";
Date date = sdfInput.parse ( textDate ) ;
System.out.println ( sdfOutput.format ( date ) ) ;
} // main
} // class DateFormatTest
Thanks and Regards
Avijit
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Bahrati,
Since your string is in the format yyyyMMdd (20061030)
In the above code use the below line
SimpleDateFormat sdfInput =
new SimpleDateFormat ("yyyyMMdd" ) ;
instead
SimpleDateFormat sdfInput =
new SimpleDateFormat ( "yyyy-MM-dd" ) ;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
please try to replace String textDate = "2001-01-04" by 20010104 and try the above sample code.
Thanks and Regards
Avijit
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.