How do I convert a Tai64 timestamp?

You can convert a Tai64 timestamp to a unix timestamp using the functions below:

function convertTaiTime(num: string){
  return BigInt(num) - BigInt(Math.pow(2, 62)) - BigInt(10);
}

function convertTime(input: BN) { 
    let bigNum = convertTaiTime(input.valueOf())
    let final =  Number(bigNum) * 1000;
    return final;
}

You can also use this converter website: https://tai64-timestamp-converter.vercel.app/

4 Likes

For those looking to do the conversion in Rust using a response received by the SDK, here’s how we do it in the forc-submit command.

This uses the chrono crate to convert the Tai64 representation to a more human readable output.

2 Likes

Does it work right? I have tried to convert 4611686020105360828 to unix with this function and it gave me 1677972914 ( which is Tue Jan 20 1970 ) , and I went to this vercel app to check if there is same, and yes, Date format is right, but unix timestamp is wrong

I’m a little confused what you mean. How did you get Tue Jan 20 1970?

i have used your formul for in js code by passing 4611686020105360828 as argument

1 Like

Ahh thanks. You just have to multiply by 1000 first. You can see the full code here: tai64-timestamp-converter/App.tsx at main · sarahschwartz/tai64-timestamp-converter · GitHub

1 Like

@sarah I’m trying to convert 4611686018427387914 from the UI that you linked and it’s not outputting anything. The code is not behaving as expected either. Can you please send me any references that you used for the function’s logic? We need to add this parsing logic to the TS SDK, so I am trying to come up with a reliable solution. Thanks!

1 Like