| Reply | « Previous Thread | Next Thread » |
|
Hi all,
In my application I displayed the current date.When I press right arrow key the date must be incremented by 1 and when I press left arrow the date must be decremented by 1.I couldn't find any method to increment and decrement date in Date ,DateField and Calendar class in j2me. Is there any solution. Please reply ... Remyag |
|
Hi Remyag,
as you say, there are no direct methods to increment/decrement dates, but you can easily implement them by using both Date or Calendar instances. When dealing with Date objects, only available method is the setTime(), that accepts as argument the date milliseconds. So, let's say you want to increment your date by 1 day, you'll do something like this: Code:
myDate.setTime(myDate.getTime() + 86400000); Dealing with Calendar instances is quite easier, since it has methods to directly modify single date fields. So, incrementing by 1 day is easy like this: Code:
yourCalendar.set(Calendar.DAY_OF_MONTH, yourCalendar.get(Calendar.DAY_OF_MONTH) + 1); Hope it helps, Pit |
|
Hi jappit,
Very Thanks for your reply... I could solved my problem. I used the code myDate.setTime(myDate.getTime() + 86400000); Thanks by Remyag |
|
Quote:
but if I need to add more than 25, like 28 for instance, results are not correct. It if your date is may 1, you will get april 9. Does anyone has a fix for this? |
|
I just solved my problem... It results that when doing 28*86400000 an overflow is produced. So I stored 86400000 in a long variable (long day = 86400000) and now 28*day does not produce overflow and it works properly.
|
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Thread | Thread Starter | Forum | Replies | Last Post |
|---|---|---|---|---|
| Beginners Tutorial for J2ME | j2meed | Mobile Java General | 1 | 2007-08-27 16:30 |
| Date in J2ME | alonish | Mobile Java General | 8 | 2007-08-07 22:07 |
| How can the WAP browser communicate to J2ME application? | hbfornies | Mobile Java General | 20 | 2007-03-02 17:32 |
| Can J2ME be used for sending MMS Message ? | seno_ap | Mobile Java General | 1 | 2006-11-24 15:36 |
| need urgent guidance on j2me | cogni_niru | Mobile Java General | 1 | 2005-11-13 16:02 |