Commit 39c991ee authored by hujiebin's avatar hujiebin

根据header的Timezone获取时区

parent 17c07ff1
package timezone_e
import "time"
import (
"regexp"
"strconv"
"time"
)
type Timezone int
......@@ -19,3 +23,15 @@ var TimezoneLocMap = map[Timezone]*time.Location{
TimezoneBeijing: BeijingTimezoneLoc,
TimezoneKSA: KSATimezoneLoc,
}
// 根据header的Timezone获取时区
// return nil: 无法解析
func GetFixedTimezone(tz string) *time.Location {
re := regexp.MustCompile(`\d+`)
timeZone := re.FindString(tz)
offset, _ := strconv.Atoi(timeZone)
if offset <= 0 {
return nil
}
return time.FixedZone("CST", offset*3600)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment