go time 包操作数据库

guoer9973 · · 1113 次点击 · · 开始浏览    
这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。

可以通过time.LoadLocation的方式避免时区的变化

func TestStatsMsg(t *testing.T) {
    assert := assert.New(t)
    assert.NotNil(QQGroupMMgr)
    ti, _ := time.Parse("2006-01-02 15:04:05", "2016-10-08 00:00:00")
    persons := QQGroupMMgr.StatsMsg("茅", ti)
    assert.NotNil(persons)
    tz, _ := time.LoadLocation("UTC")
    for _, value := range persons {
        fmt.Println("StatsMsg---:", value.ID.In(tz))
    }

}

直接取出则为:

[{2016-10-08 23:59:01 +0800 CST 1} {2016-10-08 23:58:54 +0800 CST 1} {2016-10-09 00:07:53 +0800 CST 1} {2016-10-09 00:04:09 +0800 CST 1} {2016-10-09 00:04:01 +0800 CST 1} {2016-10-09 01:35:01 +0800 CST 1} {2016-10-09 00:46:57 +0800 CST 1} {2016-10-09 00:46:47 +0800 CST 1} {2016-10-09 00:45:19 +0800 CST 1} {2016-10-09 00:37:24 +0800 CST 1} {2016-10-09 00:37:21 +0800 CST 1} {2016-10-09 00:37:14 +0800 CST 1} {2016-10-09 00:17:04 +0800 CST 1} {2016-10-09 00:14:39 +0800 CST 1} {2016-10-09 00:35:56 +0800 CST 1} {2016-10-09 00:14:03 +0800 CST 1} {2016-10-09 00:10:50 +0800 CST 1} {2016-10-09 00:10:48 +0800 CST 1}

加了八个小时

正确转换后:

yishiyaonie:collections liuhanlin$ go test -v -cover --run="TestStatsMsg"
=== RUN   TestStatsMsg
StatsMsg---: 2016-10-08 15:59:01 +0000 UTC
StatsMsg---: 2016-10-08 15:58:54 +0000 UTC
StatsMsg---: 2016-10-08 16:07:53 +0000 UTC
StatsMsg---: 2016-10-08 16:04:09 +0000 UTC
StatsMsg---: 2016-10-08 16:04:01 +0000 UTC
StatsMsg---: 2016-10-08 17:35:01 +0000 UTC
StatsMsg---: 2016-10-08 16:46:57 +0000 UTC
StatsMsg---: 2016-10-08 16:46:47 +0000 UTC
StatsMsg---: 2016-10-08 16:45:19 +0000 UTC
StatsMsg---: 2016-10-08 16:37:24 +0000 UTC
StatsMsg---: 2016-10-08 16:37:21 +0000 UTC
StatsMsg---: 2016-10-08 16:37:14 +0000 UTC
StatsMsg---: 2016-10-08 16:17:04 +0000 UTC
StatsMsg---: 2016-10-08 16:14:39 +0000 UTC
StatsMsg---: 2016-10-08 16:35:56 +0000 UTC
StatsMsg---: 2016-10-08 16:14:03 +0000 UTC
StatsMsg---: 2016-10-08 16:10:50 +0000 UTC
StatsMsg---: 2016-10-08 16:10:48 +0000 UTC
StatsMsg---: 2016-10-08 16:10:32 +0000 UTC
StatsMsg---: 2016-10-08 16:10:07 +0000 UTC
StatsMsg---: 2016-10-08 16:03:53 +0000 UTC
StatsMsg---: 2016-10-08 16:10:02 +0000 UTC
StatsMsg---: 2016-10-08 16:03:42 +0000 UTC
StatsMsg---: 2016-10-08 14:06:40 +0000 UTC
StatsMsg---: 2016-10-08 13:49:23 +0000 UTC
StatsMsg---: 2016-10-08 13:47:26 +0000 UTC
StatsMsg---: 2016-10-08 13:44:45 +0000 UTC
StatsMsg---: 2016-10-08 18:16:42 +0000 UTC
StatsMsg---: 2016-10-08 18:41:22 +0000 UTC
StatsMsg---: 2016-10-08 18:37:33 +0000 UTC
StatsMsg---: 2016-10-08 17:40:29 +0000 UTC
StatsMsg---: 2016-10-08 17:40:15 +0000 UTC
StatsMsg---: 2016-10-08 17:38:54 +0000 UTC
StatsMsg---: 2016-10-08 17:35:23 +0000 UTC
StatsMsg---: 2016-10-08 20:11:04 +0000 UTC
StatsMsg---: 2016-10-08 16:25:49 +0000 UTC
StatsMsg---: 2016-10-08 15:43:14 +0000 UTC
StatsMsg---: 2016-10-08 14:57:34 +0000 UTC
StatsMsg---: 2016-10-08 15:42:24 +0000 UTC
StatsMsg---: 2016-10-08 11:58:29 +0000 UTC
StatsMsg---: 2016-10-08 15:31:00 +0000 UTC
StatsMsg---: 2016-10-08 15:30:30 +0000 UTC
StatsMsg---: 2016-10-08 15:25:38 +0000 UTC
StatsMsg---: 2016-10-08 17:35:47 +0000 UTC
StatsMsg---: 2016-10-08 12:12:39 +0000 UTC
StatsMsg---: 2016-10-08 15:50:24 +0000 UTC
StatsMsg---: 2016-10-08 12:04:03 +0000 UTC
StatsMsg---: 2016-10-08 16:25:40 +0000 UTC
StatsMsg---: 2016-10-08 20:11:02 +0000 UTC
StatsMsg---: 2016-10-08 14:00:00 +0000 UTC
StatsMsg---: 2016-10-08 17:34:27 +0000 UTC
StatsMsg---: 2016-10-08 17:57:13 +0000 UTC
StatsMsg---: 2016-10-08 17:41:43 +0000 UTC
StatsMsg---: 2016-10-08 15:45:12 +0000 UTC
StatsMsg---: 2016-10-08 16:45:06 +0000 UTC
StatsMsg---: 2016-10-08 13:39:35 +0000 UTC
StatsMsg---: 2016-10-08 15:41:40 +0000 UTC
StatsMsg---: 2016-10-08 13:35:02 +0000 UTC
StatsMsg---: 2016-10-08 18:43:51 +0000 UTC
StatsMsg---: 2016-10-08 16:16:48 +0000 UTC
StatsMsg---: 2016-10-08 15:26:36 +0000 UTC
StatsMsg---: 2016-10-08 20:25:41 +0000 UTC
StatsMsg---: 2016-10-08 13:29:47 +0000 UTC
StatsMsg---: 2016-10-08 15:35:15 +0000 UTC
StatsMsg---: 2016-10-08 13:29:27 +0000 UTC
StatsMsg---: 2016-10-08 12:02:38 +0000 UTC
StatsMsg---: 2016-10-08 13:36:57 +0000 UTC
StatsMsg---: 2016-10-08 16:05:27 +0000 UTC
StatsMsg---: 2016-10-08 15:37:25 +0000 UTC
StatsMsg---: 2016-10-08 13:29:23 +0000 UTC
StatsMsg---: 2016-10-08 13:28:49 +0000 UTC
StatsMsg---: 2016-10-08 18:30:15 +0000 UTC
StatsMsg---: 2016-10-08 18:41:28 +0000 UTC
StatsMsg---: 2016-10-08 18:28:44 +0000 UTC
StatsMsg---: 2016-10-08 17:40:39 +0000 UTC
StatsMsg---: 2016-10-08 16:11:41 +0000 UTC
StatsMsg---: 2016-10-08 15:42:57 +0000 UTC
StatsMsg---: 2016-10-08 15:57:37 +0000 UTC
StatsMsg---: 2016-10-08 13:57:27 +0000 UTC
StatsMsg---: 2016-10-08 16:15:12 +0000 UTC
StatsMsg---: 2016-10-08 15:37:32 +0000 UTC
StatsMsg---: 2016-10-08 18:37:21 +0000 UTC
StatsMsg---: 2016-10-08 09:30:04 +0000 UTC
StatsMsg---: 2016-10-08 18:23:27 +0000 UTC
StatsMsg---: 2016-10-08 15:42:47 +0000 UTC
StatsMsg---: 2016-10-08 15:08:33 +0000 UTC
StatsMsg---: 2016-10-08 12:08:59 +0000 UTC
StatsMsg---: 2016-10-08 15:45:16 +0000 UTC
StatsMsg---: 2016-10-08 15:03:22 +0000 UTC
StatsMsg---: 2016-10-08 10:08:45 +0000 UTC
StatsMsg---: 2016-10-08 15:40:12 +0000 UTC
StatsMsg---: 2016-10-08 11:24:22 +0000 UTC
StatsMsg---: 2016-10-08 14:03:51 +0000 UTC
StatsMsg---: 2016-10-08 14:59:36 +0000 UTC
StatsMsg---: 2016-10-08 14:59:14 +0000 UTC
StatsMsg---: 2016-10-08 12:04:10 +0000 UTC
StatsMsg---: 2016-10-08 19:30:15 +0000 UTC
StatsMsg---: 2016-10-08 16:03:01 +0000 UTC
StatsMsg---: 2016-10-08 09:28:43 +0000 UTC
StatsMsg---: 2016-10-08 15:09:14 +0000 UTC
StatsMsg---: 2016-10-08 11:15:42 +0000 UTC
StatsMsg---: 2016-10-08 11:38:28 +0000 UTC
StatsMsg---: 2016-10-08 15:57:08 +0000 UTC
StatsMsg---: 2016-10-08 17:20:31 +0000 UTC
StatsMsg---: 2016-10-08 16:09:17 +0000 UTC
StatsMsg---: 2016-10-08 17:04:48 +0000 UTC
StatsMsg---: 2016-10-08 11:31:27 +0000 UTC
StatsMsg---: 2016-10-08 17:53:32 +0000 UTC
StatsMsg---: 2016-10-08 11:32:10 +0000 UTC
StatsMsg---: 2016-10-08 16:12:01 +0000 UTC
StatsMsg---: 2016-10-08 11:40:19 +0000 UTC
StatsMsg---: 2016-10-08 16:26:11 +0000 UTC
StatsMsg---: 2016-10-08 16:30:53 +0000 UTC
StatsMsg---: 2016-10-08 17:04:05 +0000 UTC
StatsMsg---: 2016-10-08 17:20:16 +0000 UTC
StatsMsg---: 2016-10-08 11:39:07 +0000 UTC
StatsMsg---: 2016-10-08 14:57:17 +0000 UTC
StatsMsg---: 2016-10-08 09:33:00 +0000 UTC
StatsMsg---: 2016-10-08 11:52:28 +0000 UTC
StatsMsg---: 2016-10-08 13:30:17 +0000 UTC
StatsMsg---: 2016-10-08 16:15:06 +0000 UTC
StatsMsg---: 2016-10-08 15:23:47 +0000 UTC
StatsMsg---: 2016-10-08 17:01:15 +0000 UTC
StatsMsg---: 2016-10-08 16:13:01 +0000 UTC
StatsMsg---: 2016-10-08 17:34:46 +0000 UTC
StatsMsg---: 2016-10-08 13:39:50 +0000 UTC
StatsMsg---: 2016-10-08 12:13:06 +0000 UTC
StatsMsg---: 2016-10-08 17:01:17 +0000 UTC
StatsMsg---: 2016-10-08 15:09:24 +0000 UTC
StatsMsg---: 2016-10-08 16:06:49 +0000 UTC
StatsMsg---: 2016-10-08 16:36:03 +0000 UTC
StatsMsg---: 2016-10-08 12:13:54 +0000 UTC
StatsMsg---: 2016-10-08 13:29:39 +0000 UTC
StatsMsg---: 2016-10-08 12:00:48 +0000 UTC
StatsMsg---: 2016-10-08 15:58:51 +0000 UTC
StatsMsg---: 2016-10-08 12:00:54 +0000 UTC
StatsMsg---: 2016-10-08 15:57:25 +0000 UTC
StatsMsg---: 2016-10-08 15:09:32 +0000 UTC
StatsMsg---: 2016-10-08 16:13:09 +0000 UTC
StatsMsg---: 2016-10-08 16:15:52 +0000 UTC
StatsMsg---: 2016-10-08 12:15:12 +0000 UTC
StatsMsg---: 2016-10-08 16:04:12 +0000 UTC
StatsMsg---: 2016-10-08 16:05:19 +0000 UTC
StatsMsg---: 2016-10-08 16:47:36 +0000 UTC
StatsMsg---: 2016-10-08 11:59:03 +0000 UTC
StatsMsg---: 2016-10-08 11:15:53 +0000 UTC
StatsMsg---: 2016-10-08 11:34:46 +0000 UTC
StatsMsg---: 2016-10-08 15:45:01 +0000 UTC
StatsMsg---: 2016-10-08 18:16:58 +0000 UTC
StatsMsg---: 2016-10-08 12:14:02 +0000 UTC
StatsMsg---: 2016-10-08 09:33:16 +0000 UTC
StatsMsg---: 2016-10-08 16:11:28 +0000 UTC
StatsMsg---: 2016-10-08 12:15:06 +0000 UTC
StatsMsg---: 2016-10-08 11:39:59 +0000 UTC
StatsMsg---: 2016-10-08 17:34:54 +0000 UTC
StatsMsg---: 2016-10-08 13:57:44 +0000 UTC
StatsMsg---: 2016-10-08 15:43:00 +0000 UTC
StatsMsg---: 2016-10-08 09:29:29 +0000 UTC
StatsMsg---: 2016-10-08 18:29:12 +0000 UTC
StatsMsg---: 2016-10-08 11:19:32 +0000 UTC
StatsMsg---: 2016-10-08 16:26:02 +0000 UTC
StatsMsg---: 2016-10-08 15:11:52 +0000 UTC
StatsMsg---: 2016-10-08 09:28:33 +0000 UTC
--- PASS: TestStatsMsg (0.01s)
PASS
coverage: 7.1% of statements
ok      mars.qiniu.com/collections  0.031s

有疑问加站长微信联系(非本文作者)

本文来自:CSDN博客

感谢作者:guoer9973

查看原文:go time 包操作数据库

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

1113 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传