javascript - Outputting human readable times from timestamps on blockchain.info -
i want parse timestamps json responses blockchain.info's api.
here example snippet https://blockchain.info/api/api_websocket
so if at
"time": 1331300839,
i try , like
var test = new date(1331300839); test.getfullyear();
and results circa 1970. i've tried using date object parse recent bitcoin transactions.. https://blockchain.info/rawaddr/1hy8lsovpit3z4qf7hr2pijxzfhzpsbaek , i'm still getting 1970.
so how human readable output these timestamps?
thanks.
if wanna format date , times, best light-weight library can find out there moment.js
var parsed = moment.unix(1331300839)
now format moment instance, use format want list: http://momentjs.com/docs/#/displaying/ or use simple yet powerful moment.tostring() or moment.fromnow()
parsed.tostring() // "fri mar 09 2012 14:47:19 gmt+0100" parsed.fromnow() // "2 years ago"
Comments
Post a Comment