Hi all,
i am using a J2ME appliation. i am able to convert date to String using Calendar. but i am not able to convert date to String in another requirement. please help me.
thanks in advance.
regards,
Bapitha .N.C
Hi all,
i am using a J2ME appliation. i am able to convert date to String using Calendar. but i am not able to convert date to String in another requirement. please help me.
thanks in advance.
regards,
Bapitha .N.C
This tutorial explains how to do that.
Hi
Thankx for the immediate reply. the problem is i am unable to import Java.text.*; and so i am unable to use SimpleDateFormat. i already tried this. please help me if their is any other alternative or should i use any other platform.
Note:
Netbeans IDE 6.0.1 is the IDE USed.
regards,
Hi bapithanc,
here's a simple method that will convert a String in "dd-mm-yyyy" format into a Date object:
Note that it does not check for any Exceptions, so you should care about them too.Code:public Date stringToDate(String s) { Calendar c = Calendar.getInstance(); c.set(Calendar.DAY_OF_MONTH, Integer.parseInt(s.substring(0, 2))); c.set(Calendar.MONTH, Integer.parseInt(s.substring(3, 5)) - 1); c.set(Calendar.YEAR, Integer.parseInt(s.substring(6, 10))); return c.getTime(); }
Also, you can easily adapt the code above to accept other date formats, just moving the substring indexes.
Hope it helps,
Pit
Hi jappit,
Thankx a lot. it helped me. i am really thank full to Nokia for providing too good Discussion Boards.
thankx again