I have two variables. weekStartDate and startDate. they both hold essentially the same timestamp:
this.startDate Date {Mon Mar 26 2012 00:00:00 GMT+0530 (IST)}
this.weekStartDate Date {Mon Mar 26 2012 00:00:00 GMT+0530 (IST)}
the problem is: when I try to getTime(), they show a slightly different value:
this.startDate.getTime() 1332700200000
this.weekStartDate.getTime() 1332700200506
how can i fix this?
I have two variables. weekStartDate and startDate. they both hold essentially the same timestamp:
this.startDate Date {Mon Mar 26 2012 00:00:00 GMT+0530 (IST)}
this.weekStartDate Date {Mon Mar 26 2012 00:00:00 GMT+0530 (IST)}
the problem is: when I try to getTime(), they show a slightly different value:
this.startDate.getTime() 1332700200000
this.weekStartDate.getTime() 1332700200506
how can i fix this?
Share Improve this question edited Mar 30, 2012 at 14:15 Th0rndike 3,4363 gold badges25 silver badges43 bronze badges asked Mar 30, 2012 at 14:12 amitamit 10.2k23 gold badges76 silver badges125 bronze badges 2-
2
User
this.weekStartDate.setMilliseconds(0)
. – Pointy Commented Mar 30, 2012 at 14:14 - Can you show how you're instantiating them? – Nik Commented Mar 30, 2012 at 14:18
2 Answers
Reset to default 6The difference is 506 milliseconds. The number of milliseconds isn’t displayed when you call toString()
on a Date
object, so anything more precise than seconds will go unnoticed unless you pare the numeric value.
To reset the milliseconds to 0
, use:
this.weekStartDate.setMilliseconds(0);
I think the milliseconds are different. Set the milliseconds of boths dates to zero then the dates will be the same:
this.weekStartDate.setMilliseconds(0);
this.startDate.setMilliseconds(0);
edit: damn i was to slow