DGomez
DGomez

Reputation: 399

Go hours minutes and seconds to just minutes with Date-fns

I have an API where they send me the format 00:25:00 and this I have to pass to a format that looks nice: like this 25:00 min what I had done is this way

const date = new Date("00:25:00");
{format(date, "h:m ")}

but I get an error, and I don't know how to pass this format 00:25:00 to minutes

Upvotes: 0

Views: 1601

Answers (1)

Lofn
Lofn

Reputation: 940

I have not tested the below one, but just try getting the minutes and seconds

const date = new Date();
const newdate = ("00" + date.getMinutes()).slice(-2) + ":" + ("00" + date.getSeconds()).slice(-2);
console.log(newdate);

If you mean to just minutes then remove the .getSeconds()

Upvotes: 1

Related Questions