According to the the following documentation (https://experienceleague.adobe.com/docs/analytics/components/metrics/time-spent-per-visit.html?lang=...), the calculation for time spent per visit is Total seconds spent divided by (Visits minus Bounces).
The below report screenshot shows a value of 293 seconds for the time spent per visit metric. But when I manually calculate using the formula above, I get a value of 212 seconds. Which one is correct and why is there a difference?
The reason there is a difference is because in out of the box time spent per visit calculation, not all visits are counted - only those that have the timespent seconds on Page attribute set. This is not exactly the same as visits - bounces. For many visits, there is no timespent set, and therefore they are not included in the avg timespent calculation. This ends up with fewer of the visits being counted than just subtracting the bounces, leading to a smaller denominator.
It should be possible to create a segment that is "visits that have timespent seconds set (great than zero)", which would allow you to get the approx same number to use as their divisor that we are.
Backend algorithm consist of some extra attributes also while calculating the metric values. Hence it is not feasible to compare the manually calculated value for metrics with the one calculated in the workspace. You will find some difference in both the calculated values.