Stack Overflow Asked by 4est on December 19, 2020
I got issue with render correct format for Firestore TimeStamp
.
I got date:
<p>{data.visitAt.toString()}<p>
value has format: Timestamp(seconds=1608276600, nanoseconds=0)
Next I did:
render(){
const optionsdate = {
year: "numeric",
month: "long",
day: "numeric",
hour: "numeric",
minutes: "numeric"
};
return(
<div>
<label>{data.visitAt.toDate().toLocaleDateString("en", optionsdate)} </label>
</div>
)
But I’m getting only:
December 18, 2020, 8 AM
How to display minutes
as well? (minuten not working)
Try this approach,
{new Intl.DateTimeFormat("en-US", options).format(data.visitAt.toDate())}
Complete code:-
export default function App() {
const options = {
year: "numeric",
month: "numeric",
day: "numeric",
hour: "numeric",
minute: "numeric",
second: "numeric"
};
return (
<div className="App">
<h1>Hello CodeSandbox</h1>
{/* 3/31/2020, 1:11:51 PM */}
<h2>{new Intl.DateTimeFormat("en-US", options).format(1585640511000)}</h2>
</div>
);
}
Codebase - https://codesandbox.io/s/epic-pike-ynqx0?file=/src/App.js
Correct answer by Sarun UK on December 19, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP