2014-09-26 66 views
-4

我有兩個變量:如何計算jquery中的時間?

start = "14:00" 
duration = "30" (minutes" 

如何計算與jQuery或Javascript的時間?因此它看起來像14:00 + 30 = 14:30

+2

是什麼?你對這個試試..? – 2014-09-26 11:44:20

回答

0

您應該所有的值轉移到秒,然後讓他們HH:MM

start = "14:00" => 14*60*60 translates to seconds 
duration = "30" = > 30*60 translates to seconds 

var theDate = (new Date).clearTime().addSeconds(57600).toString('H:mm:ss'); 

:)

date.js

+0

woooohoooooo ......好主意的人! :)謝謝你的解決方案! – Dharmana 2014-09-26 11:56:32

+0

但你能告訴我明確的代碼嗎?因爲我使用的是動態數據。起始源是$(「#timepicker1」),持續時間源是$(「dura」) – Dharmana 2014-09-26 12:59:07

+0

在時間選擇器中,您如何添加時間?用jQuery的Ui datepicker或類似的? – 2014-09-26 13:04:10