[英]LWC Date input Calculator
I am trying to get a correct outcome on difference of two dates.我正在尝试根据两个日期的差异获得正确的结果。 But when I do this I am getting a result such as (ex.10211438742389) instead of 1, 2, 3, 4, etc.. This is my JavaScript code.
但是当我这样做时,我得到的结果是 (ex.10211438742389) 而不是 1、2、3、4 等。这是我的 JavaScript 代码。
import Division from '@salesforce/schema/User.Division';
import { LightningElement, track } from 'lwc';
export default class LightningExampleInputDate extends LightningElement {
@track date1;
@track date2;
@track result;
datehandler1(event) {
this.date1 = Date.now();
console.log(event.target.value)
}
datehandler2(event) {
this.date2 = new Date(event.target.value);
console.log(event.target.value);
}
resulthandler() {
this.result = Math.abs(this.date2 - this.date1);
console.log(this.result);
}
}
I am expecting a shorter value to come out when I check the difference in-between two dates.当我检查两个日期之间的差异时,我希望得到一个更短的值。
Dates in javascripts is a representation of milliseconds starting from the epoch date , which is 1st of Jan 1970. javascripts 中的日期表示从纪元日期开始的毫秒数,即 1970 年 1 月 1 日。
If you want to calculate the difference of two dates in days , you could try this solution: https://stackoverflow.com/a/3224854/1964104如果你想计算两个日期的天数差,你可以试试这个解决方案: https://stackoverflow.com/a/3224854/1964104
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.