[英]Vue.js date off by one
我提取了 utc 日期,然后能够使日期正常工作,而不会在一天内关闭。
类似于:
<input
type="date"
name="startDate"
:value="startDate && startDate.toISOString().split('T')[0]"
@input="startDate = getDateClean($event.target.valueAsDate)"
autocomplete="off"
class="form-control"
/>
method:{
getDateClean(currDate: Date) {
// need to convert to UTC to get working input filter
console.log(currDate);
let month: number | string = currDate.getUTCMonth() + 1;
if (month < 10) month = "0" + month;
let day: number | string = currDate.getUTCDate();
if (day < 10) day = "0" + day;
const dateStr =
currDate.getUTCFullYear() + "-" + month + "-" + day + "T00:00:00";
console.log(dateStr);
const d = new Date(dateStr);
console.log(d);
return d;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.