将postgres日期表示形式转换为ISO 8601字符串 [英] Turn postgres date representation into ISO 8601 string

查看:176
本文介绍了将postgres日期表示形式转换为ISO 8601字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Postgres日期表示形式格式化为ISO 8601字符串。我假设有一个Postgres函数可以做到,但是我发现文档中缺少示例。

I'm trying to format a Postgres date representation into a ISO 8601 string. I'm assuming that there is a Postgres function that can do it, but I found the documentation short on examples.

我的查询是

SELECT
  now()::timestamp

返回

[{{2016, 8, 9}, {3, 56, 55, 754181}}]

我正在尝试将日期转换成更像
2016-8-9T03:56:55 + 00:00

I'm trying to get the date into a format that looks more like 2016-8-9T03:56:55+00:00.

我需要对查询进行哪些更改以使这种情况发生?谢谢您的帮助。

What changes do I need to make to my query to make that happen? Thanks for your help.

推荐答案

我想我找到了一种进行格式化的方法,但这并不理想,因为我正在写

I think I found a way to do the formatting, but it's not ideal because I'm writing the formatting myself.

这是一个潜在的解决方案:

Here is a potential solution:

SELECT to_char (now()::timestamp at time zone 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')

这篇关于将postgres日期表示形式转换为ISO 8601字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆