0
Help us understand the problem. What are the problem?

posted at

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

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

Register as a new user and use Qiita more conveniently

  1. You can follow users and tags
  2. you can stock useful information
  3. You can make editorial suggestions for articles
What you can do with signing up
0
Help us understand the problem. What are the problem?