tags:

views:

45

answers:

1

Here's my code:

Date aux = new Date();
TextField txtFecha = new TextField("Fecha:", aux.toString(dd/mon/yyyy), 50, TextField.ANY);

I'm trying to get my date to format like: "20/4/2010"

Thank you!

+2  A: 

You'll have to use java.util.Calendar and parse it by hand on your own. There are no library classes to help you out.

Date today = new Date();
Calendar calendar = Calendar.getInstance();
calendar.set(today);
int month = calendar.get(Calendar.MONTH) + 1;  // Java months start with Jan = 0,..., Dec = 11
int day = calendar.get(Calendar.DATE);
int year = calendar.get(Calendar.YEAR);

String dateStr = day + "/" + month + "/" + year;
duffymo
I'm new to Java, can you give me a play by play? How would I incorporate this into my code? Remember that this program is for cel phones.
Serg
I don't think Java.text is in the JavaME.
Serg
Sorry, I missed the Java ME piece.
duffymo
Please see corrections - no java.text anymore.
duffymo
Why was this downvoted again? Sergio, if you've accepted the answer why not reverse your downvote as well?
duffymo
that's really odd.. accepted with -2 :) countered one of them
Bozho