12345678910111213141516171819202122232425262728293031323334353637383940 |
- package util
- import (
- "fmt"
- "time"
- )
- const (
- LocationName = "Asia/Shanghai"
- LayoutTime = "2006-01-02 15:04:05"
- Layout = "2006-01-02"
- )
- func 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()
- }
- func 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
- }
|