英文:
How to cluster utc in milliseconds to months which belongs
问题
每个Mongo
中的文档都有以毫秒为单位的时间戳,并且我通过查询得到文档的数组作为结果。
如何将数据聚类成数组的数组
,其中内部数组是属于同一个月份的文档?
(还必须为周
做同样的操作,周从星期一
开始,最后一天是星期日
)。
英文:
Every document in Mongo
has timestamp in millisecond
s 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())
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论