Javascript 如何从firebase.firestore.FieldValue.serverTimestamp()获取日期和时间
当我在终端上记录我的创建时,它显示 “创造”:对象{ “纳秒”:420000000, “秒”:1620290402, },Javascript 如何从firebase.firestore.FieldValue.serverTimestamp()获取日期和时间,javascript,firebase,react-native,google-cloud-firestore,timestamp,Javascript,Firebase,React Native,Google Cloud Firestore,Timestamp,当我在终端上记录我的创建时,它显示 “创造”:对象{ “纳秒”:420000000, “秒”:1620290402, }, 如何将其格式化为日期和时间,以便在前端使用它以下是我过去用于Firebase到JS字符串的快速格式: //Firebase Timestamp Fix creation = new Date(creation.seconds * 1000); const formattedDate = creation.toLocaleDateString(&qu
如何将其格式化为日期和时间,以便在前端使用它以下是我过去用于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()。有关进一步的参考,请检查此源firestore查看链接的问题以及来自