mirror of
https://github.com/xinliangnote/go-gin-api.git
synced 2024-04-21 12:31:46 +00:00
34 lines
655 B
Go
34 lines
655 B
Go
package time_parse
|
|
|
|
import "time"
|
|
|
|
var (
|
|
cst *time.Location
|
|
)
|
|
|
|
// CSTLayout China Standard Time Layout
|
|
const CSTLayout = "2006-01-02 15:04:05"
|
|
|
|
func init() {
|
|
var err error
|
|
if cst, err = time.LoadLocation("Asia/Shanghai"); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// RFC3339ToCSTLayout convert rfc3339 value to china standard time layout
|
|
// 2020-11-08T08:18:46+08:00 => 2020-11-08 08:18:46
|
|
func RFC3339ToCSTLayout(value string) (string, error) {
|
|
ts, err := time.Parse(time.RFC3339, value)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return ts.In(cst).Format(CSTLayout), nil
|
|
}
|
|
|
|
func CSTLayoutString() string {
|
|
ts := time.Now()
|
|
return ts.In(cst).Format(CSTLayout)
|
|
}
|