LoginSignup
1
1

More than 5 years have passed since last update.

golang time / date まわりのメモ

Posted at

自分用メモ

iso-8601 形式の日時のパース

t, err := time.Parse(time.RFC3339Nano, "2013-06-05T14:10:43+09:00")
fmt.Println(t)
// => 2013-06-05 14:10:43 +0900 +0900

指定した日時の1日、前月の1日

now := time.Now()

// 当月1日
a := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())

// 前月1日
b := a.AddDate(0, -1, 0)

fmt.Println(a)
fmt.Println(b)
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1