【问题标题】:Using Firerstore Timestamp in datetime-local Input在 datetime-local 输入中使用 Firerstore 时间戳
【发布时间】:2019-08-24 01:37:03
【问题描述】:

我从 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".

【问题讨论】:

    标签: javascript timestamp google-cloud-firestore


    【解决方案1】:

    已解决。

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

    【讨论】:

      猜你喜欢
      • 2021-04-03
      • 2015-09-14
      • 1970-01-01
      • 1970-01-01
      • 2020-08-27
      • 1970-01-01
      • 2023-04-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多