Gorm 查询时间RFC3339格式转为标准时间格式

最近在开发接口的过程中,发现从数据库里获取的列表数据在输出后时间格式为RFC3339,数据库时间字段为timestemp是正常的,需要转换标准时间格式后输出:
{“data”:[{“id”:11,“name”:“浦电路店”,“company_id”:“63”,“code”:"",“open_status”:1,“hours_desc”:“周一到周日09:00到21:00”,“store_type”:1,“created_time”:“2016-09-23T17:41:47Z”},{“id”:12,“name”:“宜山路店”,“company_id”:“63”,“code”:"",“open_status”:1,“hours_desc”:“周一到周日09:30到21:00”,“store_type”:1,“created_time”:“2017-07-22T12:32:37Z”}],“message”:“success”,“total”:2}
RFC3339时间格式:“created_time”:“2017-07-22T12:32:37Z”
标准时间格式格式:“created_time”:“2017-07-22 12:32:37”

转换方法一:
转换如下 : 需要转换的时间变量为 toFormatTime
res_time,_:=time.Parse(“2006-01-02T15:04:05Z07:00”, toFormatTime)
toFormatTime = res_time.Format(“2006-01-02 15:04:05”)
时间 “2006-01-02 15:04:05” 是固定写法

转换方法二:
queryTime.Format(“2006-01-02 15:04:05”)

这样输出的时间格式就是标准时间格式了
{“data”:[{“id”:11,“name”:“浦电路店”,“company_id”:“63”,“code”:"",“open_status”:1,“hours_desc”:“周一到周日09:00到21:00”,“store_type”:1,“created_time”:“2016-09-23 17:41:47”},{“id”:12,“name”:“宜山路店”,“company_id”:“63”,“code”:"",“open_status”:1,“hours_desc”:“周一到周日09:30到21:00”,“store_type”:1,“created_time”:“2017-07-22 12:32:37”}],“message”:“success”,“total”:2}

其实两种方法的实现本质是一样的


版权声明:本文为u014459543原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。