2020年5月12日日期轉時間戳golang

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章