Data type for storing date time offset in golang

huangapple go评论75阅读模式
英文:

Data type for storing date time offset in golang

问题

我正在使用Go语言开发一个应用程序。在我的程序中,我接收到一个包含日期时间偏移格式实体的JSON数据,例如DateTime": "2014-10-19T23:08:24Z"

我需要将JSON数据解析并以TIMESTAMP(p) WITH TIME ZONE格式存储在PostgreSQL数据库中。当我解析时,我需要将其存储在相同数据类型的变量中。

在Golang中是否有可用的数据类型来实现这一点,或者是否有其他方法可以实现这一点?

英文:

I am using go language to develop an application. In my program I receive a JSON data which contains an entity in date time offset format for example DateTime": "2014-10-19T23:08:24Z"

I need to unmarshal the JSON and store it in the database in the TIMESTAMP(p) WITH TIME ZONE format in PostgreSQL database. When I unmarshal, I need to store this in a variable of the same data type.

Is there a data type available in Golang to do this or any other means of doing this?

答案1

得分: 2

time.Time 结构体能够感知时区,并且大多数可用的 SQL 驱动程序都能正确处理它。

唯一需要补充的是,在大多数系统中,约定俗成的做法是在交换格式(JSON、SQL 等)中仅使用 UTC 日期,并在必要时让应用程序进行时区转换。

英文:

The time.Time struct is aware of the timezone, and should be properly handled by most of the SQL drivers available.

The only thing to add is that the convention in most systems is to use only UTC dates in exchange formats (JSON, SQL, etc) and let the application shift to timezone when necessary.

huangapple
  • 本文由 发表于 2015年3月4日 19:49:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/28853714.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定