0

I have an AngularJS App which requests data from another system. One part of the Data is a time (independent from the day) in 24hr format with Seconds and milliseconds like this:

11:15:00.000

Whats the best way to format it with Javascript / AngularJS to a format like this:

11:15

Greetings

3

1 Answer 1

2

If the format is always the same, you can simply limit it to 5 characters using a built-in Angular filter and the resulting string will always be in hh:mm format, i.e.:

<span>{{'11:15:00.000' | limitTo:5}}</span>

Will output 11:15.

You can use this filter inside the js code like that:

var d = $filter('limitTo')('11:15:00.000', 5);

If the format might be different, then you should use something like moment.js

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.