Hello friends,
I want to know the current time(hh:mm:ss) of device by writing simple midlet. I dont know how to proceed. could you please tell me how to achieve this?
Hello friends,
I want to know the current time(hh:mm:ss) of device by writing simple midlet. I dont know how to proceed. could you please tell me how to achieve this?
This code should work for you:
If you want 12h-based hour, you can get it with c.get(Calendar.HOUR) and check if is AM/PM with the Calendar.AM_PM property.Code:Date d = new Date(); Calendar c = Calendar.getInstance(); c.setTime(d); String time = c.get(Calendar.HOUR_OF_DAY) + ":" + c.get(Calendar.MINUTE) + ":" + c.get(Calendar.SECOND);
Pit
Hi jappit,
thanks for your reply, but when I executed the application as you suggestd, its working fine on emulator, but when istalled on Nokia E61i and Nokia 6300, it is not installing and showing an error message : application not compatible with this phone.
my code is :
public class DateAndTime extends MIDlet implements CommandListener
{
Display disp;
Form form = new Form("Data and Time");
Command start = new Command("start", Command.SCREEN, 1);
Command exit = new Command("Exit", Command.EXIT, 0);
Date d ;
Calendar c = Calendar.getInstance();
String time;
public void startApp()
{
form.append("TIME IS : ");
form.addCommand(start);
form.addCommand(exit);
form.setCommandListener(this);
disp = Display.getDisplay(this);
disp.setCurrent(form);
}
public void pauseApp()
{
}
public void destroyApp(boolean uncond)
{
}
public void commandAction(Command cmd, Displayable s)
{
if (cmd == exit)
{
notifyDestroyed();
}
else
if (cmd == start)
{
d = new Date();
c.setTime(d);
time = c.get(Calendar.HOUR_OF_DAY) + ":" +c.get(Calendar.MINUTE) + ":" + c.get(Calendar.SECOND);
form.append("" + time);
form.append("\n");
}
}
}
what is the problem?
Which CLDC and MIDP versions are you using? Also, are you using any non-standard APIs (even if it seems you're not from your code)?
Pit
CLDC 1.1 and MIDP 2.1
I am using only standard APIs.
Both Nokia E61i and 6300 support MIDP 2.0, not MIDP 2.1, so you should change that setting. To be sure about phone specifications and supported APIs, always check here:
http://www.forum.nokia.com/devices/matrix_all_1.html
Pit
Though I changed the emulator settings to MIDP 2.0, it still shows the same error message.
Thankyou jappit,
now i changed the emulator settings as suggested you.
now it is installed on my devices.
once again thanks for quick response.
One more doubt, when I started the midlet on my mobile, the current time is 15:59:1.
and the midlet shows the current time as 15:29:01.
I dont know why there is a difference of 30 minutes.
what might be the problem? any suggestions?
Mumble... do both phones give you the wrong time? Or one only (which one)?
Could be related
http://wiki.forum.nokia.com/index.ph...on_S60_MIDlets
Hartti
Thank you very much Hartti for your quick response.