i want to figure out the time from the beginning of the day given a days milliseconds.
so say i'm given this: 1340323100024 which is like mid day of 6/21/2012. now i want the milliseconds from the beginning of the day, which would be 1340262000000 (at least i think that's what it's supposed to be.)
how do i get 1340262000000 from 1340323100024?
i tried doing
Math.floor(1340323100024/86400000) * 86400000
but that gives me 1340236800000, which if i create a date object out of it, says its the 20th.
i know i can create a date object from 1340323100024, then get the month, year, and date, to create a new object which would give me 1340262000000, but i find it ridiculous i can't figure out something so simple.
any help would be appreciated.
btw, i'm doing this in javascript if it makes any difference.
Actually, it should be
(currTimeMilli - 18000000) % 864000000
to get the number of milliseconds since the beginning of the day for GMT+5.I agree with Thilo (localized to time zone), but I'd probably tackle it like this:
Or, if you prefer:
EDIT
If you're particular about the timezone, you can use:
Notice that the offset is now removed so the 8pm the previous day turns in to midnight of the actual day on the timestamp. You can also probably (depending on implementation) do the addition before or after you modulo for the beginning of the day--your preference.