Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

h:mm:ss to seconds and vice versa #704

Closed
fxck opened this issue Apr 2, 2013 · 8 comments
Closed

h:mm:ss to seconds and vice versa #704

fxck opened this issue Apr 2, 2013 · 8 comments

Comments

@fxck
Copy link

fxck commented Apr 2, 2013

Is there any way to get seconds from say 5:45:15?

@timrwood
Copy link
Member

timrwood commented Apr 2, 2013

This is being added with this pull request. #702

moment.duration("5:45:15").asSeconds();

In the meantime, I suppose you could use something like this as a workaround.

var a = moment.utc('5:45:15', 'H:mm:ss'),
    b = a.clone().startOf('day');
return a.diff(b, 'seconds');

@fxck
Copy link
Author

fxck commented Apr 2, 2013

and the other way around? second to h:mm:ss?

@ichernev
Copy link
Contributor

ichernev commented Apr 3, 2013

d = moment.duration({s: 1000});
moment().startOf('day').add(d).format('HH:mm:ss')

that won't work for more than 24 hours though.

@fxck
Copy link
Author

fxck commented Apr 3, 2013

So momentjs as it is, is not quite the right tool for this kind of stuff..

@ichernev
Copy link
Contributor

ichernev commented Apr 3, 2013

Well, as @timrwood said there is a patch comming that would enable one of the conversions. About the other way around -- there is a way to humanize a duration, but it won't be in a specific format. There was some discussion (#463) about controlling the formatting of humanize, but nothing implemented yet. If you have a specific proposal for an api I'll be glad to hear it.

@fxck
Copy link
Author

fxck commented Apr 3, 2013

What would be nice is you said here #704 (comment) only if you could call .format() directly on duration like this moment.duration({s: 1000}).format('HH:mm:ss');..

@ichernev
Copy link
Contributor

ichernev commented Apr 6, 2013

This sounds like a feature request. Can you form it as such and specify format tokens/semantics.

@icambron
Copy link
Member

Closing this in favor of #1048.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants