0

I'm using React JS to create an App. During the process, I've created a component "Card Component" that I'm calling on the App.js. The mission of that component is to print details in a card. So far, everything is working fine, except the date! As you can see on the prints that I have below... I've tried a few different approaches, but I'm stuck! I can't think of anything else and my knowledge is still short! I've managed to console.log the third one with a string that is the accurate date that I need, however, I'm not being able to transform it to a date&time format!

Code:

enter image description here

Console.log

enter image description here

Michael Nelles
  • 5,426
  • 8
  • 41
  • 57
  • 1
    https://stackoverflow.com/questions/4673527/converting-milliseconds-to-a-date-jquery-javascript asked and answered – mAsTeRoFnOne Apr 07 '20 at 11:17
  • Does this answer your question? [Converting milliseconds to a date (jQuery/JavaScript)](https://stackoverflow.com/questions/4673527/converting-milliseconds-to-a-date-jquery-javascript) – VilleKoo Apr 07 '20 at 11:18

1 Answers1

1

Change your <h4> to include

<h4>{console.log("third:",new Date(new Date().getTime(`${props.country.updated}``)).toString())}</h4>

You can also use customFormat for your use-case

<h4>{console.log("third:",new Date().customFormat("#DD#/#MM#/#YYYY#"))}</h4>
FYP ACM
  • 46
  • 4
  • Thank you for your answer. You pointed me on the correct direction, however, with a slight difference. {console.log(new Date(new Date(props.country.updated).toString()))} With that I'm being able to print to the console.log the time that is stored on "updated". Now a new problem happens! Using:

    {new Date(new Date(props.country.updated).toString())}

    I'm getting an error: Error: Objects are not valid as a React child (found: Tue Apr 07 2020 15:47:06 GMT+0100 (British Summer Time)). If you meant to render a collection of children, use an array instead. Any idea?
    – AlbertoFerreira Apr 07 '20 at 14:54