Add multiple TimeSpans together with datejs
I'm using the JavaScript library datejs and in particularly the TimeSpan class.
I've got it all work开发者_StackOverflow中文版ing great for one TimeSpan. However I need it to add together the results of multiple TimeSpans on the page. My code is below:
var monTimeSpan = new TimeSpan(Date.parse($("#monFinish").val()) - Date.parse($("#monStart").val()))
var tueTimeSpan = new TimeSpan(Date.parse($("#tueFinish").val()) - Date.parse($("#tueStart").val()))
These work great but I need to add the result of the Tuesday TimeSpan to the Monday one.
Any help would be great.
Thanks
The TimeSpan
object includes the .add()
function.
The following sample demonstrates adding two TimeSpan
objects together.
Example
var t1 = new TimeSpan(Date.today().add(5).days() - Date.today());
var t2 = new TimeSpan(Date.today().add(10).days() - Date.today());
var total = t1.add(t2);
total.days // 15
精彩评论