javascript - 如何在时刻以小时格式减去两个小时格式
问题描述
let dayDuration = "23:59:59";
let anotherhour ="04:00:00";
moment.duration(moment(dayDuration, "hh:mm:ss").diff(anotherhour));
如何在循环中增加先前的值:
假设第一次迭代持续时间值为 10,第二次迭代持续时间值为 30,它应该添加为 40。
hasEvnets.map(x=>{
var dayDuration = x.startTime;
var anotherHour=x.endTime;
var remainingtime+= moment.duration(moment(dayDuration, "hh:mm:ss").diff(anotherhour));
});
和
moment(moment("00:00:00", "HH:mm:ss").diff(moment("18:00:00", "HH:mm:ss"))).format("HH:mm:ss");
moment(moment("00:00:00", "HH:mm:ss").diff(moment("18:00:00", "HH:mm:ss"))).utc().format("HH:mm:ss"); -06:00:00
which produces 00:00:00 as o/p but i need -18:00:00 how to do that formatting.
在 C# 中,效果很好。
var dayDuration = new TimeSpan(00, 00, 00).Subtract(Convert.ToDateTime("2019-02-01 18:00:00").TimeOfDay);
Console.WriteLine(dayDuration);
我已经试过了。
让 n = moment.duration(moment("00:00:00", "HH:mm:ss").diff(moment("18:00:00", "HH:mm:ss")));
控制台.log(n);
我需要以下格式。18:00:00
http://jsfiddle.net/5103y2du/4/
Atlast 我找到了解决方案,但解决方案并不好。
让 n = moment.duration(moment("00:00:00", "HH:mm:ss").diff(moment("18:00:00", "HH:mm:ss")));
工作正常
let z = n.hours();
let y = n.minutes();
let u = n.seconds();
console.log(z+":0"+y+":0"+u);
-- 不工作
使用时刻需要相同
console.log(moment(n.hours).format("hh:mm:ss"));
解决方案
你anotherhour
是一个string
,所以它不能正常工作。
尝试这个:
moment(moment(dayDuration, "HH:mm:ss").diff(moment(anotherhour, "HH:mm:ss"))).utc().format('HH:mm:ss')
推荐阅读
- c# - IIS下远程调试ASP.Net Core 2.2 + .Net framework
- sql - VBA、Access 和 SQL 的新手。我如何编写一个 SQL 查询来搜索我的 AccessDB 中的一个表并在找到它时给我一个 True/False?
- ios - 如何从 PhotoLibrary 存储所选视频的位置
- plotly-python - 如何使用 plotly 定义子图的布局
- java - 选择在 iOS 中未显示的特定移动元素,然后对其执行点击操作
- swift - 当用户位置改变时调用 mapView(_:viewFor:)
- c++ - 在编译时将整数和分数部分宏组合成一个新宏或双精度
- windows - 如何获取目录中具有特定扩展名的所有文件?
- excel - 对多列中的数据进行排序
- sql-server - 带有百分位问题的 SQL 自定义排序顺序