32 lines
770 B
Go
Raw Permalink Normal View History

2022-01-26 16:40:50 +08:00
package util
import "time"
const (
TimeFormat = "2006-01-02 15:04:05"
TimeFormatDay = "20060102"
TimeFormatDay2 = "2006-01-02"
TimeFormatDay3 = "2006/01/02"
2022-03-16 16:04:29 +08:00
TimeFormatDay4 = "2006.01.02_15"
2022-01-26 16:40:50 +08:00
)
/**
* 二个时间戳是否同一天
* @return true false 不是今天
*/
func IsSameDay(oldDay, anotherDay int64) bool {
tm := time.Unix(oldDay, 0)
tmAnother := time.Unix(anotherDay, 0)
if tm.Format(TimeFormatDay2) == tmAnother.Format(TimeFormatDay2) {
return true
}
return false
}
/**字符串->时间对象*/
2022-03-16 16:04:29 +08:00
func Str2Time(formatTimeStr, timeFormat string) time.Time {
2022-01-26 16:40:50 +08:00
loc, _ := time.LoadLocation("Local")
theTime, _ := time.ParseInLocation(timeFormat, formatTimeStr, loc) //使用模板在对应时区转化为time.time类型
return theTime
2022-03-16 16:04:29 +08:00
}