0

I want to get the timestamp of the block in Seconds but eosjs library returns it in an iso string format. Is there a way to receive timestamp in seconds or convert the string to seconds?

Example: What I get:

block_time: '2021-03-12T05:45:56.000'

What I want:

block_time in seconds.

1

You can pass block_time string to instantiate Date object. It contains milliseconds, so you need to divide it by 1000 to get seconds.

code:

const block_time = '2021-03-12T05:45:56.000';
const seconds = Math.floor(new Date(block_time) / 1000);
console.log(seconds);

output:

1615527956

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.