【发布时间】:2021-01-23 12:32:32
【问题描述】:
将输入类型时间转换为 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();
这是预期的结果
这是我的代码
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);
});
}
【问题讨论】:
-
您预期的时间戳输出是多少?
-
您需要输入的值,而不是 html 元素。此外,将它传递给 moment 会给你一个 moment 对象。您可能想节省纪元时间。
-
$('#starttimeadd').val()。字符串中的值是什么 -
@naveen 01:00 同上,是使用html5输入时间
标签: javascript html firebase google-cloud-firestore