gpt4 book ai didi

javascript - 将输入类型时间转换为 firestore 的时间戳

转载 作者:行者123 更新时间:2023-12-03 06:59:39 25 4
gpt4 key购买 nike

将输入类型时间转换为 firestore 的时间戳

<input type="time" class="form-control job-field" id="starttime" name="starttimeadd" placeholder="Job Start Time" required>
这是我尝试过但没有运气的方法,我确实有一些尝试不同方法的结果,但显示日期或 NaN 无效。
var starttimestamp = moment.utc(moment("#starttimeadd")).format();
这是预期的结果
enter image description here
这是我的代码
function addJob(){


var starttimeadd = $('#starttimeadd').val();

const starttimestamp = moment.utc(moment(starttimeadd)).format();


db.collection("jobs").doc().set({

starttime: starttimestamp,

})

.then(function() {
console.log("Document successfully written!");
})
.catch(function(error) {
console.error("Error writing document: ", error);
});

}

最佳答案

moment将日期作为参数,而不是像您在这里尝试做的元素 ID。怎么样:

const startTimeAdd = document.getElementById("starttimeadd").value;
const starttimestamp = moment.utc(startTimeAdd).format();
同样值得考虑的是,您可能不需要为此使用 Moment - 官方文档推荐阅读 why you may not need Moment 上的文章。

关于javascript - 将输入类型时间转换为 firestore 的时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64262891/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com