Created
August 22, 2018 08:52
-
-
Save dgarcia360/349e8ba55eccbde70da1518890ea4293 to your computer and use it in GitHub Desktop.
NEM Uint64 timestamp to Date
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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