Get the the timeStamp for the transaction

Hi, I want to get the timeStamp for Transaction, if I don’t want to get it from the api:GET /node/extended-info, which way can I use to get it? Can someone help to show the code snippet about it? thank you very much.

1 Like

Timestamp for a new connection can be deducted from the request

http://alice2.nem.ninja:7890/time-sync/network-time

The returned timestamps need to be divided by 1000 since they represent milliseconds and the tx timestamp is in seconds.

2 Likes

Thanks for your reply. Is there other way to get it if I don’t want to use http request?

Maybe the nem-sdk is supporting retrieving the network time, i haven’t looked at it.

Yeah, me too. I want to get the network time by using the nem core code or sdk. But not found yet. Anybody else know this? thanks a lot.

Just to be clear. You want calculate timestamp to set in newly created transaction?
If yes best way is to fetch it from /time-sync/network-time (receiveTimeStamp). This is how nanowallet does.

Yeah, agree with you. thanks.

function nemtimestamp()
{
var now = new Date();
var nemepoch = new Date(“March 29, 2015 00:06:25 -0000”);
return Math.round((now-nemepoch)/1000);
}

2 Likes

Exactly. But using local time can cause problem because on NIS time can be different and transaction may be rejected if difference is to big.