显示来自 TimeStamp 的分钟数(React、TimeStamp、Firestore)

Display minuten from TimeStamp (React, TimeStamp, Firestore)

我在 Firestore TimeStamp.

的正确渲染格式方面遇到问题

我得到了日期:

<p>{data.visitAt.toString()}<p>

值的格式为:Timestamp(seconds=1608276600, nanoseconds=0)

接下来我做了:

render(){

        const optionsdate = {
            year: "numeric",
            month: "long",
            day: "numeric",
            hour: "numeric",
            minutes: "numeric"
        };

return(
   <div>
     <label>{data.visitAt.toDate().toLocaleDateString("en", optionsdate)}&nbsp;</label>
   </div>
)

但我只得到:

December 18, 2020, 8 AM 

如何显示minutes? (分钟不工作)

试试这个方法,

{new Intl.DateTimeFormat("en-US", options).format(data.visitAt.toDate())}

完整代码:-

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>
  );
}

代码库 - https://codesandbox.io/s/epic-pike-ynqx0?file=/src/App.js