How do I convert a Tai64 timestamp?

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

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

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