Link to home
Start Free TrialLog in
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 ?
Avatar of Zakaria Acharki
Zakaria Acharki
Flag of Morocco image

I suggest to you the use of MomentJS Library that allows you to simply Parse, validate, manipulate, and display dates and times in JavaScript.
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.
Avatar of Alex Lord
Alex Lord

ASKER

okay so how do i do that ? moments is time span
Hae? Time spans in MomentJS are called durations.
ASKER CERTIFIED SOLUTION
Avatar of Zakaria Acharki
Zakaria Acharki
Flag of Morocco image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Question
How do you want this to be displayed
12:00:22
Or this
12:23:00
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.
hmm, Howard's answer makes me think:

@Alex: Do you have a time, thus a Date, or a string?
it only a string this time