github.com/chanxuehong/wechat@v0.0.0-20230222024006-36f0325263cd/mch/core/time.go (about)

     1  package core
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/chanxuehong/wechat/util"
     7  )
     8  
     9  // FormatTime 将参数 t 格式化成北京时间 yyyyMMddHHmmss.
    10  func FormatTime(t time.Time) string {
    11  	return t.In(util.BeijingLocation).Format("20060102150405")
    12  }
    13  
    14  // ParseTime 将北京时间 yyyyMMddHHmmss 字符串解析到 time.Time.
    15  func ParseTime(value string) (time.Time, error) {
    16  	return time.ParseInLocation("20060102150405", value, util.BeijingLocation)
    17  }