| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 | package utilimport (	"fmt"	"time")const (	LocationName = "Asia/Shanghai"	LayoutTime   = "2006-01-02 15:04:05"	Layout       = "2006-01-02")// TimeParseLocalUnix 获取当天零点的时间戳// eg 2023-02-22 => 1676995200func TimeParseLocalUnix(DayTime string) int64 {	value := DayTime	if len(DayTime) <= 11 {		value = fmt.Sprintf("%s 00:00:00", DayTime)	}	loc, _ := time.LoadLocation("Local")	theTime, _ := time.ParseInLocation(LayoutTime, value, loc)	return theTime.Unix()}// TimeParseLocalEndUnix 获取当天24点的时间戳// eg 2023-02-22  => 1676995200func TimeParseLocalEndUnix(DayTime string) int64 {	value := DayTime	if len(DayTime) <= 11 {		value = fmt.Sprintf("%s 23:59:59", DayTime)	}	loc, _ := time.LoadLocation("Local")	theTime, _ := time.ParseInLocation(LayoutTime, value, loc)	return theTime.Unix()}// ConvertParseLocalUnix 字符串转换当天时间戳// eg 15:04:05 => 1676998245func ConvertParseLocalUnix(timeParse string) (int64, error) {	loc, err := time.LoadLocation("Local")	if err != nil {		return 0, err	}	value := fmt.Sprintf("%s %s", time.Now().Format(Layout), timeParse)	theTime, err := time.ParseInLocation(LayoutTime, value, loc)	if err != nil {		return 0, err	}	return theTime.Unix(), nil}// GetMonthRemainDay 获取当前月还剩几天func GetMonthRemainDay() int {	now := time.Now()	lastDayOfMonth := time.Date(now.Year(), now.Month()+1, 0, 23, 59, 59, 999999999, now.Location())	return int(lastDayOfMonth.Sub(now).Hours()/24) + 1}
 |