2020年5月12日轉時間戳
代碼如下
package main
import (
"fmt"
"strings"
"time"
)
func dateToTimestamp() (dateTimestamp int64) {
date := "2020年5月12日"
date = strings.Replace(date, "年", "-", 1)
date = strings.Replace(date, "月", "-", 1)
date = strings.Trim(date, "日")
stamp, _ := time.ParseInLocation("2006-1-2", date, time.Local)
dateTimestamp = stamp.Unix()
return dateTimestamp
}
func main() {
fmt.Println(dateToTimestamp())
}
輸出結果:1589212800