LoginSignup
0
0

More than 1 year has passed since last update.

【備忘録】Golangで文字列型(YYYY-MM)から月を取得する

Posted at
main.go
package main

import (
	"fmt"
	"strconv"
)
func main() {
	// YYYY-MM形式から月を保存する。
	str := "2021-04"
	str2 := str[5:]
	month, _ := strconv.Atoi(str2)
	fmt.Println("month: ",month)

	str = "2021-12"
	str2 = str[5:]
	month, _ = strconv.Atoi(str2)
	fmt.Println("month: ",month)
}
実行結果
~/go/src/array_slice $ go run main.go
month:  4
month:  12
0
0
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
0
0