I have a postgresql db with the columns date and repeat_until as timestamp with time zone. The example dates have a time zone specific format. The latter is winter time.
2017-08-28 09:00:00+02
, 2017-12-31 23:00:00+01
Using string and time.Time the first gives the time relative to GMT+0, the latter seconds (not unix timestamp).
import (
_ "github.com/lib/pq"
"fmt"
"github.com/gorilla/mux"
"github.com/jmoiron/sqlx"
"log"
"net/http"
"time"
)
type Event struct {
Date string
RepeatUntil time.Time `db:"repeat_until"`
}
event := Event{}
rows, _ := db.Queryx("select * from events order by date")
for rows.Next() {
err := rows.StructScan(&event)
if err != nil {
log.Fatalln(err)
}
fmt.Printf("%#v", event)
}
Date:"2017-08-28T07:00:00Z"
RepeatUntil:time.Time{sec:63650354400, nsec:0, loc:(*time.Location)(nil)}
What is the recommended way to retain time zone information? time.Time seems obvious but I am not sure how it got to seconds which is in year 3986 in unixtime.
I'm using sqlx.