丢弃时间戳中的毫秒部分 [英] Discard millisecond part from timestamp
本文介绍了丢弃时间戳中的毫秒部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何丢弃/舍入 millisecond
部分,如果 second
部分也从 timestamp
w/o 中删除会更好>时区
?
How can I discard/round the millisecond
part, better if the second
part is also removed from a timestamp
w/o timezone
?
推荐答案
A cast to timestamp(0)
或 timestamptz(0)
舍入到整秒:
A cast to timestamp(0)
or timestamptz(0)
rounds to full seconds:
SELECT now()::timestamp(0);
分数不存储在这种类型的表列中.
Fractions are not stored in table columns of this type.
date_trunc()
截断(保持秒数不变)——这通常是您真正想要的:
date_trunc()
truncates (leaves seconds unchanged) - which is often what you really want:
SELECT date_trunc('second', now()::timestamp);
这篇关于丢弃时间戳中的毫秒部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文