我在我的vue.js代码(使用element.io)中分别使用日期选择器和时间选择器,给我的值为: date =“2018-01-19T00:00:00.000Z”time = "2018-05-20T00:06:30.000Z“,日期和时间都是对象形式.现在我要创建新对象dataTime = "2018-01-19T00:06:30.000Z“
如何创建此文件,然后将其转换为ISOStrinh格式?
发布于 2022-03-07 10:17:54
这里的大多数答案都没有将夏时制考虑在内。如果日期和时间不在相同的夏时制规则中,则用T来确定日期和时间会给出一个不正确的结果。根据时区规则,您的时间将是一个小时的休息。以下是避免日光节约问题的简单方法:
const mergeDateAndTime = (date, time) => {
const newDate = new Date(date);
newDate.setHours(time.getHours());
newDate.setMinutes(time.getMinutes());
newDate.setSeconds(time.getSeconds());
newDate.setMilliseconds(0);
return newDate;
};https://stackoverflow.com/questions/48398565
复制相似问题