Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data type for storing date time offset in 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?

like image 381
Aishwarya Gopalakrishnan Avatar asked Oct 31 '22 08:10

Aishwarya Gopalakrishnan


1 Answers

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.

like image 147
Elwinar Avatar answered Nov 13 '22 15:11

Elwinar