to_char()

用于格式化日期、时间戳和数字类型的函数

to_char() 是一个系统函数,用于将日期、时间戳和数值以指定格式输出。

to_char() 函数在 PostgreSQL 7.0 中被添加。

用法

to_char ( timestamp, text ) → text
to_char ( timestamp with time zone, text ) → text
to_char ( interval, text ) → text
to_char ( numeric_type, text ) → text

to_char() 将提供的值转换为指定的模板格式;有关详细信息,请参阅 PostgreSQL 文档中 日期/时间格式的模板模式 部分。

变更历史

进行中

示例

使用 to_char() 格式化时间戳的基本示例

postgres=# SELECT to_char(now(), 'YYYY-MM-DD HH24:MI');
     to_char      
------------------
 2021-08-01 10:02
(1 row)

分类

日期和时间, 字符串操作

另请参阅

to_timestamp(), to_date(), to_number()

反馈

请在此处提交关于 "to_char()" 的任何评论、建议或更正 here