Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

String to String (Date conversion)

  Asked By: Caleb    Date: Apr 16    Category: Java    Views: 1053
  

How can I convert 11022004 to 11/02/2004.

Share: 

 

5 Answers Found

 
Answer #1    Answered By: Vinit Online     Answered On: Apr 16

Date d=new SimpleDateFormat("ddMMyyyy").parse("11022004");

 
Answer #2    Answered By: Jake Williams     Answered On: Apr 16

> How can I convert  11022004 to 11/02/2004.

public String getFormatedDate (String inDate, String inFormat,
String outFormat) throws ParseException {
String outDate = "";

SimpleDateFormat dtFormat = new SimpleDateFormat
(inFormat); //"ddMMyyyy"
try {
Date date  = dtFormat.parse(inDate);
dtFormat.applyPattern(outFormat); //dd/MM/yyyy
outDate = dtFormat.format(date);
}
catch (ParseException pe) {
System.err.println("Format for Entered date is
incorrect");
throw pe;
}
return outDate;
}

For formats, refer to
java.sun.com/.../SimpleDateFormat.ht
ml

 
Answer #3    Answered By: Muriel Dunn     Answered On: Apr 16

i am a beginner in J2ME.I have a form but the user in unable to enter a avlid
date in it.
Plz help me.

 
Answer #4    Answered By: Trae Thompson     Answered On: Apr 16

can you tell me whether there is a Focus() type command in J2ME as is in
javascript.
if yes, then plz tell me the syntax.

 
Answer #5    Answered By: Rochelle Elliott     Answered On: Apr 16

If its fixed length, you could use something as simple as:

String oldDate = "11022004";
String newString = oldDate.substring(0, 2) + "/" +
oldDate.substring(2, 4) + "/" + oldDate.substring(4);

 
Didn't find what you were looking for? Find more on String to String (Date conversion) Or get search suggestion and latest updates.




Tagged: