What is the most efficient and syntactically elegant way to determine the half way point between two dates in Javascript.
var difference = date2.getTime() - date1.getTime();
var midpoint = new Date(date1.getTime() + difference / 2);
Is this a good approach?
That is indeed the most efficient way, with one correction:
var midpoint = new Date((date1.getTime() + date2.getTime()) / 2);
The mid-point is the average of the two points.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With