After authenticating through Firebase, one of the timestamp fields from the user data when console logged shows up as Fri Dec 02 2022 11:50:37 GMT-0700 (Mountain Standard Time)
. I haven't had the need to process any timestamps on my project so I just left that as is.
I tried to fetch data from my Firestore that included another timestamp field and somehow I get a different format. It shows as:
ut {seconds: 1670006748, nanoseconds: 11000000}
Is there a way for me to ensure that any timestamps coming from Firebase are returned to my application in a consistent format? I will eventually write a utility file on my React project to handle all of my date/time needs and I just want to be ready when I get to that point.
CodePudding user response:
Have you tried fetching the timestamp to try to convert it?
Sample code:
// to get as date
const date = new TimeStamp(yourTimeStamp.seconds , yourTimeStamp.nanoseconds).toDate();
// to get as string
const date = new TimeStamp(yourTimeStamp.seconds , yourTimeStamp.nanoseconds).toDate().toDateString();