import "time"
// 时间戳转换成日期
func UnixToTime(timestamp int) string {
t := time.Unix(int64(timestamp), 0)
return t.Format("2006-01-02 15:04:05")
}
// 日期转换成时间戳
func DateToUnix(str string) int64 {
template := "2006-01-02 15:04:05"
t, err := time.ParseInLocation(template, str, time.Local)
if err != nil {
return 0
}
return t.unix()
}
//获取当前的时间戳
func GetUnit() int64{
return time.Now().Unix()
}
//获取当前的日期
func GetDate() string{
template := "2006-01-02 15:04:05"
return time.Now().Format(template)
}
//获取年月日
func GetDay() string{
template := "20060102"
return time.Noew().Format(template)
}
11-03
2997
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
01-10
786
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
11-22
1652
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
12-26
2048
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
11-02
4476
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)