Angular2 + How to display milliseconds from a date?

I used a custom channel to display time, and now I tried to change it to display milliseconds:

{{log.LogDate|jsonDate|date:'dd.MM.yyyy   HH:mm:ss.sss'}}

The pipe itself:

if (typeof (value) === 'string') {
        if (value.includes('/Date('))
            return  new Date(parseInt(value.substr(6)));
    }
    return value;

However, milliseconds have seconds:

log.LogDate: 2017-05-08T15: 45: 38.2527293+ 02:00

Out of the pipe: 05/08/2017 15: 45: 38.38

Full pipe jsonDate (without format): 2017-05-08T15: 45: 38.2527293 + 02: 00

I'm new to Javascript and I'm not sure if this is a problem with Javascript or Angular, however I would like it to work inside Angular. Is it possible to do this with pipes, or is there another / better way to do this?

+4
source share
3 answers

angular 5 SSS, .
. https://angular.io/api/common/DatePipe


,

{{log.LogDate|jsonDate|date:'dd.MM.yyyy   HH:mm:ss.SSS'}}



angular 5:
 - [...]
 - S SSS.
 - [...]

+1

Angular. AngularJS , Angular (2+) (GH issue). date . , , . , . . - Moment.js :

moment(value).format('DD.MM.YYYY HH:mm:ss.SSS');

, Angular, ( ), , .

+3

, javascript-:

{{ Datetime | date:'dd.MM.yyyy HH:mm:ss' }}.{{ getMillies(Datetime) }}

----

public getMillies(input: Date): number
{
    return new Date(input).getMilliseconds();
}

Angular 5 runs a new data pipe to support M

0
source

Source: https://habr.com/ru/post/1676655/


All Articles