gpt4 book ai didi

momentjs - 如何转换时间(hh :mm) to decimal form with momentjs

转载 作者:行者123 更新时间:2023-12-04 05:06:58 26 4
gpt4 key购买 nike

使用Moment.js将小时分钟转换为十进制时间的最佳方法是什么

假设我有1:30分钟,我想在转换后有1.5分钟

这是我尝试过的

console.log(travelTime().split(':')[0]);   return 1
console.log(travelTime().split(':')[1]); return 30 then / 30

其中travelTime()==“1:30”

最佳答案

看起来您想要的是moment.duration(durationAsString)来解析您的持续时间,而.asHours()则要格式化为小数。
moment.duration('1:30').asHours();将返回1.5

有关更多信息,请参见有关持续时间的Moment文档部分:http://momentjs.com/docs/#/durations/

关于momentjs - 如何转换时间(hh :mm) to decimal form with momentjs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21255268/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com