Ai
1 Star 0 Fork 0

cube-lab/tcb-openapi

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
helpers.go 1.21 KB
一键复制 编辑 原始数据 按行查看 历史
evansleiliu 提交于 2021-04-05 10:36 +08:00 . init
package util
import (
"encoding/json"
"strings"
"time"
)
//模拟三元操作
func If(b bool, t, f interface{}) interface{} {
if b {
return t
}
return f
}
//格式化时间
func Format(t *time.Time) (v string) {
if t != nil {
return t.Format("2006-01-02 15:04:05")
}
return
}
//时间字符串转换成时间对象
func StrToTime(s string) *time.Time {
loc, _ := time.LoadLocation("Local")
t, _ := time.ParseInLocation("2006-01-02 15:04:05", s, loc)
return &t
}
//时间字符串转换成时间对象
func Time() *time.Time {
t := time.Now()
return &t
}
//获取毫秒
func Millisecond() int64 {
var cstSh, _ = time.LoadLocation("Asia/Shanghai") // 上海
return time.Now().In(cstSh).Unix() * 1000
}
//格式化时间
func Date() (v string) {
var cstSh, _ = time.LoadLocation("Asia/Shanghai") // 上海
return time.Now().Local().In(cstSh).Format("2006-01-02")
}
//转JSON
func JsonEncode(v interface{}) string {
if v == nil {
return ""
}
j, e := json.Marshal(v)
if e != nil || strings.Compare(string(j), "null") == 0 {
return ""
}
return string(j)
}
//转JSON
func JsonDecode(s string, out interface{}) error {
e := json.Unmarshal([]byte(s), out)
if e != nil {
return e
}
return nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/cubelab/tcb-openapi.git
git@gitee.com:cubelab/tcb-openapi.git
cubelab
tcb-openapi
tcb-openapi
41edef41dc45

搜索帮助