Skip to content

Instantly share code, notes, and snippets.

@dgarcia360
Created August 22, 2018 08:52
Show Gist options
  • Save dgarcia360/349e8ba55eccbde70da1518890ea4293 to your computer and use it in GitHub Desktop.
Save dgarcia360/349e8ba55eccbde70da1518890ea4293 to your computer and use it in GitHub Desktop.
NEM Uint64 timestamp to Date
import {BlockchainHttp, UInt64} from 'nem2-sdk';
const blockchainHttp = new BlockchainHttp('http://localhost:3000');
const timestampToDate = (timestamp: UInt64): Date => {
const timestampNemesisBlock = 1459468800;
const dateSeconds = timestamp.compact();
return new Date(Math.round(dateSeconds + timestampNemesisBlock * 1000));
};
blockchainHttp.getBlockByHeight(2)
.subscribe(block => console.log(timestampToDate(block.timestamp)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment