Avatar of Alex Lord
Alex Lord
 asked on

Formatting time

Dev Question

So i have this data coming from a table which is a time 00:03:22.

how can i format this in js to the user to be like 3min 22 seconds ?
JavaScript

Avatar of undefined
Last Comment
Alex Lord

8/22/2022 - Mon
Zakaria Acharki

I suggest to you the use of MomentJS Library that allows you to simply Parse, validate, manipulate, and display dates and times in JavaScript.
ste5an

Just a comment: don't mix time with time spans. They are different data types.

Your given data looks like time, but a formatting in minutes and seconds denotes a time span. E.g. 11:35:22 vs. 695min 22sec.
Alex Lord

ASKER
okay so how do i do that ? moments is time span
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
ste5an

Hae? Time spans in MomentJS are called durations.
ASKER CERTIFIED SOLUTION
Zakaria Acharki

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Julian Hansen

Question
How do you want this to be displayed
12:00:22
Or this
12:23:00
Howard Bash

If you guarantee that the incoming format is hh:mm:ss then you could use the split function and build the string.  That would be the simpliest way ASSUMING the format is as stated.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ste5an

hmm, Howard's answer makes me think:

@Alex: Do you have a time, thus a Date, or a string?
Alex Lord

ASKER
it only a string this time