Angular date filter does not work with Stripe timestamp

I have a timestamp provided by the Stripe API. 1397166153.

However, when using it in its simplest form, {{ 1397166153 | date }}I get: January 17, 1970, when in fact it should be April 10, 2014.

Does anyone know what is going on here?

I really appreciate your help!

+4
source share
2 answers

I always run all my timestamps through a function, since the JavaScript era is in milliseconds and the Stripe response era is in seconds.

$scope.timestamp = function(epoch){
    return (epoch * 1000);
};

Then in your template:

 <p>{{ timestamp(1397166153) | date }}</p>

Alternatively, if you just need to do this once, you can always do it inline:

 <p>{{ (1397166153 * 1000) | date }}</p>
+6

, .

var seconds = 1397166153; //your value
var ms = seconds * 1000;

new Date(seconds) // Fri Jan 16 1970 21:06:06 GMT-0700 (Mountain Standard Time)
new Date(ms) // Thu Apr 10 2014 15:42:33 GMT-0600 (Mountain Daylight Time)

, Stripe . Date ms Angular.

+2

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


All Articles