Files
web_huakui_server/pub/common/timehelper.go
rootandClaude Opus 4.7 85c0071fd8 feat: 从黄果 NET hgdjnet-server 9bfbafe 导入 HKDJ 官网后端
来源:hgdjnet-server 9bfbafe10d417deea959bd53117bc88a10e60a83
项目身份 HKDJ / JHA-216,独立官网仓库,Jenkins 守卫键 hkdjnet
测试目录 /server/hkdj_net,App/Web API 30331/30332

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-10-16 11:20:04 +08:00

56 lines
1.3 KiB
Go

package common
import (
"path/filepath"
"strings"
"time"
)
func BindUrl(hostname string, path ...string) string {
if hostname == "" {
return strings.TrimLeft(filepath.Join(path...), "/")
}
if len(path) == 0 {
return hostname
}
su := strings.TrimLeft(filepath.Join(path...), "/")
pr := strings.TrimRight(hostname, "/")
return pr + "/" + su
}
// 将time.Time转换成int64
func Time2Stamp(t time.Time) int64 {
return t.UnixNano() / 1e9
}
/**时间对象->字符串*/
func Time2Str() string {
const shortForm = "2006-01-01 15:04:05"
t := time.Now()
temp := time.Date(t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second(), t.Nanosecond(), time.Local)
str := temp.Format(shortForm)
return str
}
/*时间戳->字符串*/
func Stamp2Str(stamp int64) string {
timeLayout := "2006-01-02 15:04:05"
str := time.Unix(stamp/1000, 0).Format(timeLayout)
return str
}
/*时间戳->时间对象*/
func Stamp2Time(stamp int64) time.Time {
stampStr := Stamp2Str(stamp)
timer := Str2Time(stampStr)
return timer
}
/**字符串->时间对象*/
func Str2Time(formatTimeStr string) time.Time {
timeLayout := "2006-01-02 15:04:05"
loc, _ := time.LoadLocation("Local")
theTime, _ := time.ParseInLocation(timeLayout, formatTimeStr, loc) //使用模板在对应时区转化为time.time类型
return theTime
}