sarah
February 17, 2023, 10:16pm
1
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.
use std::fmt::Write;
match status {
TransactionStatus::Submitted { submitted_at } => {
writeln!(s, "Transaction Submitted at {:?}", submitted_at.0)?;
}
TransactionStatus::Success {
block_id,
time,
program_state,
} => {
let utc = chrono::Utc.timestamp_nanos(time.to_unix());
writeln!(s, "Transaction Succeeded")?;
writeln!(s, " Block ID: {block_id}")?;
writeln!(s, " Time: {utc}",)?;
writeln!(s, " Program State: {program_state:?}")?;
}
TransactionStatus::SqueezedOut { reason } => {
writeln!(s, "Transaction Squeezed Out: {reason}")?;
}
TransactionStatus::Failure {
block_id,
This uses the chrono
crate to convert the Tai64 representation to a more human readable output.
2 Likes
sway
March 5, 2023, 6:37am
3
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
sarah
March 5, 2023, 5:53pm
4
I’m a little confused what you mean. How did you get Tue Jan 20 1970?
sway
March 5, 2023, 11:04pm
5
i have used your formul for in js code by passing 4611686020105360828 as argument
1 Like
sarah
March 5, 2023, 11:57pm
6
1 Like