firebaseとdate型 firebaseに保存されている日付データの型はいくらか種類があるので調べる
認証時に保存されるユーザ作成日
const admin = require('firebase-admin')
admin.auth().listUsers.filter(user => {
console.log(user.metadata.creationTime) // javascriptのdate型
})
databaseに保存される日付のフィールド フロントエンド側でnew Date()を与えてもdatabaseではTimestamp型として保存される
const collections = await admin.firestore().collection('collections').get()
collections.docs.filter(collection => {
console.log(collection.data().createdAt) // Timestamp型
console.log(collection.data().createdAt.toDate()) // javascriptのdate型
})
GMT+0000(UTC)の時刻が取得される
const today = new Date()
console.log(today) // ex.2020-01-01T15:36:00.639Z
firebase console(GUI)上ではGMT+0900(日本標準時)に合わせた時刻が表示されているが、 firebaseから取得するとGMT+0000(UTC)の時刻となっている
const collections = await admin.firestore().collection('collections').get()
collections.docs.filter(collection => {
console.log(collection.data().createdAt.toDate()) // ex.2020-01-02T15:36:00.639Z
})