1

Hello Guys!

I just wrote some code with JavaScript and Firebase, I obtained the date from Firebase in milliseconds and converted it to date format with this code.

const dateObject = new Date(milliseconds)

const humanDateFormat = dateObject.toLocaleString("en-US", {day: "numeric"}) + '/' + dateObject.toLocaleString("en-US", {month: "numeric"})  + '/' + dateObject.toLocaleString("en-US", {year: "numeric"});

Now I cant find the way back with this kind of date format I used. I want to edit the product but when I try to convert this date I can´t find a useful method.

Maybe should I use LocalStorage to storage the date in milliseconds then search for it and use it?

Thanks anticipated!

Regards, Gaspar.

Zeta
  • 25
  • 6
  • https://stackoverflow.com/questions/3830244/get-current-date-time-in-seconds I think thats what you are searching for.(?) – h0p3zZ Jul 24 '21 at 14:31
  • Which format do you want the string in? You can try `toISOString()`, `toString()` methods on `dateObject` if they satisfy the need. – Dharmaraj Jul 24 '21 at 14:33
  • You are likely best to store the original value. However converting a timestamp in d/m/y format is not difficult: `let [d, m, y] = date.split(/\D/); new Date(y, m-1, d).getTime()` will return the time value for that date. – RobG Jul 25 '21 at 23:38

0 Answers0