在datetime-local输入中使用Firerstore时间戳

时间:2019-04-02 16:35:33

标签: javascript timestamp google-cloud-firestore

我正在从Firestore获取时间戳,并试图填充日期时间输入字段。我正在使用moment.js格式化日期。

<input id="time" type="datetime-local" placeholder="Event date/time">

JS

var time = docData.time.toDate();
console.log(time);
var formattedDate = moment(time).format('yyyy-MM-DD hh:mm');
console.log(formattedDate);
document.getElementById("time").value = formattedDate.toLocaleString();

记录“时间”变量的结果

Wed Nov 28 2018 14:00:00 GMT-0500 (Eastern Standard Time)

记录“ formattedDate”的结果

yyyy-11-28 02:00

控制台中的警告消息。

events.js:85 The specified value "yyyy-11-28 02:00" does not conform to the required format.  The format is "yyyy-MM-ddThh:mm" followed by optional ":ss" or ":ss.SSS".

1 个答案:

答案 0 :(得分:0)

已解决此问题。

var formattedDate = moment(time).format("YYYY-MM-DDTkk:mm");