Javascript, GetTime ()

I am trying to understand something about getTime(), My problem is, I am setting a new date , and say: 23.07.2012 . When I use getTime(), I have to get milliseconds since 01.01.1970. When I divide the value that I get from getTime()with (1000 * 60 * 60 * 24) , I have to get the number of days elapsed from 01.01.1970 until 05.07.22012 , but somehow I get the number with a decimal point (15543.875) I donโ€™t understand why, I mean, starting from 01.01.1970 strong> and 23.07.22012 I have to get an integer (this is what I think), I know that I am really mistaken if someone can help me understand why the decimal point is the result.

+5
source share
1 answer

If you set the type date new Date(2012, 06, 23), it will be set according to the clientโ€™s time zone, where .getTime()- UTC. Do you want Date.UTC:

Date.UTC(2012,6,23) / (1000*60*60*24)
//15544 For any computer

new Date(2012, 06, 23) / (1000*60*60*24)
//15543.875 For my computer, I am coincidentally in  the same timezone as Israel. This result will depend on what timezone the client is.
+4
source

All Articles