简体   繁体   English

如何在javascript中将时间字符串与时间字符串相加?

[英]How can I sum a time with a time string in javascript?

i would like to sum this time 15-00-00 with this which is a string: 4 minutes I don't know how to convert the 4 minutes into a correct format and the 15-00-00 into 15:00:00 我想把这个时间用15-00-00加上这是一个字符串: 4 minutes我不知道如何将4 minutes转换为正确的格式, 15-00-00转换为15:00:00

here's my code : 这是我的代码:

var reservationDate = '<?= $selectDateReservation[0] ?>';
var reservationTime = '<?= $selectTimeReservation[0] ?>';
var getDuration = '<?= $selectDuration[0] ?>' // returns: "4 minutes"
console.log(reservationDate); // returns the date: 19-05-17
console.log(reservationTime); // returns the time: 15-00-00

Try something like this 尝试这样的事情

var date = new Date();
var minutes = 4

date.setMinutes(date.getMinutes() + minutes);
console.log(date) // Should return your time with the minutes added to it

You could convert the minutes with the getMinutes() method. 您可以使用getMinutes()方法转换分钟。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM