AnswerBun.com

Display minuten from TimeStamp (React, TimeStamp, Firestore)

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)}&nbsp;</label>
   </div>
)

But I’m getting only:

December 18, 2020, 8 AM 

How to display minutes as well? (minuten not working)

One Answer

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

Add your own answers!

Related Questions

Red box isn’t placed as expected

1  Asked on November 4, 2021 by liya-thomas

       

String Comparison Javascript

2  Asked on November 4, 2021 by crimsonpython24

       

es5 using promise but returns defered before resolving

2  Asked on November 4, 2021 by rodney-wormsbecher

     

2 arrays with json problem (Node.js, Discord.js)

3  Asked on November 4, 2021 by mr-code

     

Is there a XAML equivalent to nameof?

2  Asked on November 4, 2021 by luxun

       

Multistage builds with yum

3  Asked on November 4, 2021 by vorticity

 

WooCommerce can’t see product variations

1  Asked on November 4, 2021 by tizio-fittizio

       

VScode setup with ROS and auto complete

3  Asked on November 4, 2021 by dixcipuli

         

Pick an account after Connect-MicrosoftTeams

4  Asked on November 4, 2021 by mauek-unak

   

Show local image file:///tmp/someimage.jpg

1  Asked on November 4, 2021 by dani-herrera

   

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP