I have a LWUIT code that supposed to print today date .
The problem with me is the date printed in "Mon dd hh:mm:ss GMT+...... yyyy" format
e.g Thu Nov 28 01:00:00 GMT+03:00 2013
So I have a couple of questions
How to get the format in "yyyy-mon-dd" format.
how to add a day to the today date after conversion to "yyyy-mon-dd" .
Observe that some classes wouldn't work in J2ME like Simpledateformat class.
import javax.microedition.midlet.*;
import com.sun.lwuit.*;
import com.sun.lwuit.events.*;
public class myLibrary extends MIDlet {
Form f;
com.sun.lwuit.Calendar cal;
Button b;
public void startApp() {
com.sun.lwuit.Display.init(this);
f = new com.sun.lwuit.Form();
cal = new com.sun.lwuit.Calendar();
b = new Button("Enter");
f.addComponent(cal);
f.addComponent(b);
b.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent acv) {
System.out.println(""+cal.getDate());
}
});
f.show();
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}
In order to use the
java.lwuit.Calendar
class, to get your date in that format you will need to substring the data from thecal.getDate()
.for example
Doing that, you will get your data and after that reorder them in a String.
To change the Date from the Calendar view you will need to use Calendar.setDate(Date d);
I suggest you to use java.util.Calendar
If you still want to use the
Date
class, try this code, it will print the tomorrow day