【发布时间】:2021-07-30 16:00:05
【问题描述】:
当我在终端上控制台记录我的创建时,它会显示
“创造”:对象{ “纳秒”:420000000, “秒”:1620290402, },
如何将其格式化为日期和时间,以便在前端使用它
【问题讨论】:
-
查看google.com/…的链接问题及更多内容
标签: javascript firebase react-native google-cloud-firestore timestamp
当我在终端上控制台记录我的创建时,它会显示
“创造”:对象{ “纳秒”:420000000, “秒”:1620290402, },
如何将其格式化为日期和时间,以便在前端使用它
【问题讨论】:
标签: javascript firebase react-native google-cloud-firestore timestamp
这是我过去用于 Firebase 到 JS 字符串的一种快速格式:
//Firebase Timestamp Fix
creation = new Date(creation.seconds * 1000);
const formattedDate = creation.toLocaleDateString("en-US");
const formattedTime = creation.toLocaleString('en-US', { hour: 'numeric', minute: 'numeric', hour12: true });
const newDate = `${formattedDate} ${formattedTime}`;
【讨论】:
javascript 对 firebase 时间戳一无所知。它只是为您提供对象
所以只需使用 toDate()。 如需进一步参考,请查看此来源toDate()firestore
【讨论】: