I have a timestamp supplied by Stripe's API. 1397166153.
However when using it in the most simplest form {{ 1397166153 | date }}
I get: Jan 17, 1970 when in fact it should be Apr 10, 2014.
Does anyone know what's going on here?
I really appreciate your help!
I always run all of my timestamps through a function, as JavaScript epoch is in milliseconds, and the Stripe response epoch is in seconds.
$scope.timestamp = function(epoch){
return (epoch * 1000);
};
Then, in your template:
<p>{{ timestamp(1397166153) | date }}</p>
Alternatively, if you need to just do it once, you can always do it inline:
<p>{{ (1397166153 * 1000) | date }}</p>
It appears that the timestamp is in Seconds.
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)
I'm not sure what format Stripe sends it back in. But I've always had to convert to a Date
object or to ms
to work with Angular date filters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With