Inconsistent results from date additions loop

by Dexter's Brain » Mon, 07 Dec 2009 19:38:16 GMT


Sponsored Links
 Doing it the millisecond way might be more confortable.

Convert both the dates to milliseconds, and then subtract one from the
other, and then calculate the no of days.

Thanks
Kumar Bibek
 http://tech-droid.blogspot.co 




--



Inconsistent results from date additions loop

by Streets Of Boston » Tue, 08 Dec 2009 00:51:33 GMT


 You don't know how many milliseconds there are in a day, or even how
many hours there are.

Most days have 24 hours, one may have 23 and an other may have 25
hours ( DST ). And this depends whether your timezone has DST or not.
The Calendar class should be able to figure all this out.

However, if you're just interested in 'before' or 'after', then
comparing the dates using the milliseconds is OK, since you don't need
to know the exact amount.

Andrew, post a code snippet and describe exactly what problem you see.





--


Sponsored Links


Inconsistent results from date additions loop

by andrew android » Mon, 14 Dec 2009 05:34:43 GMT


 he code is something like this...

public void getWorkDays(final int mm, final int dd,final int ccyy,
final int mmNew, final int ddNew, final int ccyyNew) {

Calendar c2 = Calendar.getInstance();
Calendar c4 = Calendar.getInstance();

c2.set(ccyy, mm, dd);
c4.set(ccyyNew,mmNew, ddNew);
c2.setFirstDayOfWeek(1);
c4.setFirstDayOfWeek(1);

Integer counter = 0;

while (c4.after(c2)) {

switch (c2.get(Calendar.DAY_OF_WEEK)){
case 1:

c2.add(Calendar.DATE, 1);
break;
case 2:

counter = counter + 1;
c2.add(Calendar.DATE, 1);
break;
case 3:
counter = counter + 1;

c2.add(Calendar.DATE, 1);
break;
case 4:
counter = counter + 1;
c2.add(Calendar.DATE, 1);
break;
case 5:
counter = counter + 1;
c2.add(Calendar.DATE, 1);
break;
case 6:
counter = counter + 1;
c2.add(Calendar.DATE, 1);
break;
case 7:
c2.add(Calendar.DATE, 1);
break;

}
}

WorkDaysCalc=counter;

}


On Dec 7, 10:51am, Streets Of Boston <flyingdutc...@gmail.com> wrote:

--



Inconsistent results from date additions loop

by andrew android » Mon, 14 Dec 2009 05:43:18 GMT


 Thanks for responding... the code is the following :
        public void getWorkDays(final int mm,  final int dd,final int ccyy,
                        final int mmNew, final int ddNew, final int ccyyNew) {

                Calendar c2 = Calendar.getInstance();
                Calendar c4 = Calendar.getInstance();

                c2.set(ccyy, mm, dd);
                c4.set(ccyyNew,mmNew, ddNew);
                c2.setFirstDayOfWeek(1);
                c4.setFirstDayOfWeek(1);

                Integer counter = 0;
                while (c4.after(c2)) {

                        switch (c2.get(Calendar.DAY_OF_WEEK)){
                        case 1:
                                        c2.add(Calendar.DATE, 1);
                                        break;
                        case 2:
                                        counter = counter + 1;
                                c2.add(Calendar.DATE, 1);
                                break;
                        case 3:
                                        counter = counter + 1;
                                c2.add(Calendar.DATE, 1);
                                break;
                        case 4:
                                        counter = counter + 1;
                                c2.add(Calendar.DATE, 1);
                                break;
                        case 5:
                                        counter = counter + 1;
                                c2.add(Calendar.DATE, 1);
                                break;
                        case 6:
                                        counter = counter + 1;
                                c2.add(Calendar.DATE, 1);
                                break;
                        case 7:
                                c2.add(Calendar.DATE, 1);
                                break;

                        }
                }

                WorkDaysCalc=counter;

        }

--



Inconsistent results from date additions loop

by andrew android » Mon, 14 Dec 2009 19:48:52 GMT


  seem to have resolved it b y replacing the call to the method after
with a comparison.
Thanks everyone!


On Dec 12, 12:13pm, andrew android <andygoldm...@gmail.com> wrote:

--



Other Threads

1. OOT: Paging bos Lucky

Bwahahhaha, kali ini saya nyatakan otentik! Ngga mungkin bajaj jelek gitu
ada di spore, klo di museum pasti bagus, klo jelek gitu terkubur di dasar
laut yg ditumpuk dalam pasir dr kepulauan riau jadi pemekaran wilayah
spore...
Hidup bajaj...!

Eh hidup N1....!

Ngeces ..ces...ces...ces...




Mmm...
Berhubung ga nemu batagor...
Poto di samping bajaj aja yah...

Hahahahahaha



Sent from my Anjroid
www.jeruknipis.com
--
=========================
Google Groups "Indonesian Android Community [id-android]" group.

To post to this group, send email to id-android@googlegroups.com

To request to subscribe to this group:

Click  

2. Silahkan datang, Gathering ID-Android With XL, Mingguu, 17 Januari 2010

Pak Arif yang baik,

Silahkan datang, tapi mohon maaf jika nanti tidak dapat makanan dll, karena
keterbatasan. Saya percaya jangan melihat makanan gratisnya, tapi
kebersamaan dan sharing ilmu.

Hari/Tanggal   :  Minggu, 17 Januari 2010
Waktu             :  13:00 s/d 16:00  WIB
Tempat           : Soho Music Cafe, Lantai 5  Senayan City



2010/1/11 Arief Burhanuddin <arief.burhanud...@gmail.com>

>

3. Media Flinger Crash on Camera picture taken (picture sound) on Nexus One

4. ListView touch mode click on child views

5. auto paring feature

6. Restoring focus to ListView

7. (was OOT: Clear coat by showcase fever)