[英]How can I get the difference in the two dates in js which are in string?
I have a certain format which is in the我有某种格式,在
{
"updatedAt": "2022-01-04 22:41:32.268897",
"status": "open",
"createdAt": "2022-01-04 22:41:26.328339"
}
I want to get the difference in hours or minutes of both the dates I tried many but didn't get the expected result.我想得到我尝试了很多但没有得到预期结果的两个日期的小时或分钟差异。
You can use the Date module in javascript.您可以在 javascript 中使用 Date 模块。
const obj = { "updatedAt": "2022-01-04 22:41:32.268897", "status": "open", "createdAt": "2022-01-03 22:41:26.328339" };
const updatedAt = new Date(obj.updatedAt);
const createdAt = new Date(obj.createdAt);
const diffInMilliSecs = updatedAt - createdAt;
This difference is in milliseconds.这种差异以毫秒为单位。 You can now convert this into seconds or minutes or hours.您现在可以将其转换为秒或分钟或小时。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.