
エントリーの編集

エントリーの編集は全ユーザーに共通の機能です。
必ずガイドラインを一読の上ご利用ください。
【Golang】sort.Sliceでtime.Time型のスライスをソート - Qiita
記事へのコメント0件
- 注目コメント
- 新着コメント
このエントリーにコメントしてみましょう。
注目コメント算出アルゴリズムの一部にLINEヤフー株式会社の「建設的コメント順位付けモデルAPI」を使用しています

- バナー広告なし
- ミュート機能あり
- ダークモード搭載
関連記事
【Golang】sort.Sliceでtime.Time型のスライスをソート - Qiita
package main import ( "fmt" "time" "sort" ) type User struct { Name string CreatedAt time.Time } ... package main import ( "fmt" "time" "sort" ) type User struct { Name string CreatedAt time.Time } func main() { us := []User{ { Name: "john", CreatedAt: time.Now().Add(time.Minute), }, { Name: "kenta", CreatedAt: time.Now(), }, } fmt.Println(us) sort.Slice(us, func(i, j int) bool { return us[i].CreatedAt.Before(us[j].CreatedAt) }) fmt.Println(us) } // Sort前 // [{john 2009-11-10 23:01:00 +0000 UTC m