【发布时间】:2022-10-25 19:36:44
【问题描述】:
我正在使用 NEAR 协议的这个公共 Postgres DB:https://github.com/near/near-indexer-for-explorer#shared-public-access
有一个名为 included_in_block_timestamp 的字段,其“数据类型”=“数字”,“长度/精度”=20。
此代码有效:
to_char(TO_TIMESTAMP("public"."receipts"."included_in_block_timestamp"/1000000000), 'YYYY-MM-DD HH:mm') as moment,
这也是:
function convertTimestampDecimalToDayjsMoment(timestampDecimal: Decimal) {
const timestampNum = Number(timestampDecimal) / 1_000_000_000; // Why is this necessary?
console.log({ timestampNum });
const moment = dayjs.unix(timestampNum); // https://day.js.org/docs/en/parse/unix-timestamp
return moment;
}
例如,有时included_in_block_timestamp = 1644261932960444221。
我从未见过需要除以 10 亿的时间戳。刚刚弄清楚这一点是一个反复试验的问题。
这里发生了什么?这是常见的做法吗?这种精度水平是否有意义?
【问题讨论】:
-
那是纳秒分辨率,文档说它应该只是 1us 分辨率。
-
什么种类你认为可能会发生什么?要将纳秒转换为秒,您需要除以十亿。这不是神秘主义,它只是算术。
-
1644261932960444221 不是一个“时间戳”开始 - 它只是一个数字
标签: postgresql timestamp unix-timestamp nearprotocol