如何将属于毫秒级的 UTC 时间聚类到月份中?

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

How to cluster utc in milliseconds to months which belongs

问题

每个Mongo中的文档都有以毫秒为单位的时间戳,并且我通过查询得到文档的数组作为结果。
如何将数据聚类成数组的数组,其中内部数组是属于同一个月份的文档?
(还必须为做同样的操作,周从星期一开始,最后一天是星期日)。

英文:

Every document in Mongo has timestamp in milliseconds and I get array of documents as result of query.
How to cluster data to array of arrays where inner array are documents which belongs to same month ?
( Have to to do this also for weeks, week starts at Monday and the last day is Sunday).

答案1

得分: 1

你可以使用time包来获取月份和星期几:

package main

import "fmt"
import "time"

func main() {
    ms := int64(0)
    t := time.Unix(0, ms*int64(time.Millisecond))
    fmt.Println(t.Month(), t.Weekday())
}

你可以在这里运行这段代码:http://play.golang.org/p/cPRXZyFnTA

英文:

You can get the month and weekday with the time package:

package main

import "fmt"
import "time"

func main() {
	ms := int64(0)
	t := time.Unix(0, ms*int64(time.Millisecond))
	fmt.Println(t.Month(), t.Weekday())
}

http://play.golang.org/p/cPRXZyFnTA

huangapple
  • 本文由 发表于 2015年7月13日 21:42:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/31385033.html
匿名

发表评论

匿名网友

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

确定