MySQL ISO 8601日期带时区偏移而不是Z值 [英] MySQL ISO 8601 Date with Timezone offset instead of Z value

查看:686
本文介绍了MySQL ISO 8601日期带时区偏移而不是Z值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要选择ISO 8601日期。

I need to SELECT a ISO 8601 Date.

DATE_FORMAT(date, '%Y-%m-%dT%TZ') 

这样会产生类似于

2013-11-13T15:47:530Z

但是需要使用偏移而不是Z值:

But I need it with the offset instead of Z value:

2013-11-13T15:47:53+02:00

我可以用简单的MySQL做这个吗?

How can I do this with plain MySQL ?

推荐答案

您需要将时区作为DB中的额外列存储。我不知道使用时区/偏移量存储datetime 的数据库。

You need to store the timezone as an extra column in DB. I do not know any DB that stores datetime with timezone/offset.

或将日期存储为具有偏移量的ISO 8601格式的字符串。

Or store the date as string in ISO 8601 format with offset..

编辑:我有点纠正,有些较新的数据库是可能的!

I stand somewhat corrected, with some newer databases it is possible!


  • Postgresql日期/时间类型,确实可能包含时区。

    • 数据类型:时间戳[(p)],时区仅用于输入和输出,它存储在UTC。

    • 数据类型:时间与时区,只有时间,存储时区偏移。 自版本8起

    • Postgresql Date/Time Types, which indeed may include timezone.
      • Datatype: "timestamp [ (p) ] with time zone" only for input and output, it is stored in UTC.
      • Datatype: "time with time zone", only time, stores timezone offset. Since version 8.
      • Datatype: "TIMESTAMP WITH TIME ZONE", stores timezone offset. Since version 9i.
      • Datatype: "TIMESTAMP WITH TIME ZONE", stores timezone offset or timezone name. Since version 10g.
      • See also Oracle TIMESTAMP WITH TIMEZONE named zone vs offset.

      • 数据类型:datetimeoffset,存储时区偏移量。


      • 数据类型:TIMESTAMP WITH TIME ZONE,存储时区偏移量。

      • 支持TIMESTAMP WITH TIME ZONE是SQL / 2008标准的可选SQL语言功能F411。

      似乎实际上有些标准 SQL99

      不适用于 Mysql 。版本5.6。

      Not for Mysql. Version 5.6.

      我确实觉得安慰是因为纠正来自我自己; - )

      I do find consolation in the fact that the correction came from myself ;-)

      这篇关于MySQL ISO 8601日期带时区偏移而不是Z值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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