feat: omc原始代码

This commit is contained in:
TsMask
2024-03-12 10:58:33 +08:00
parent 5133c93971
commit 2d01bb86d1
432 changed files with 66597 additions and 1 deletions

View File

@@ -0,0 +1,70 @@
package date
import (
"fmt"
"time"
"nms_nbi/lib/log"
)
const (
// 年 列如2022
YYYY = "2006"
// 年-月 列如2022-12
YYYY_MM = "2006-01"
// 年-月-日 列如2022-12-30
YYYY_MM_DD = "2006-01-02"
// 年月日时分秒 列如20221230010159
YYYYMMDDHHMMSS = "20060102150405"
// 年-月-日 时:分:秒 列如2022-12-30 01:01:59
YYYY_MM_DD_HH_MM_SS = "2006-01-02 15:04:05"
)
// 格式时间字符串
//
// dateStr 时间字符串
//
// formatStr 时间格式 默认YYYY-MM-DD HH:mm:ss
func ParseStrToDate(dateStr, formatStr string) time.Time {
t, err := time.Parse(formatStr, dateStr)
if err != nil {
log.Infof("utils ParseStrToDate err %v", err)
return time.Time{}
}
return t
}
// 格式时间
//
// date 可转的Date对象
//
// formatStr 时间格式 默认YYYY-MM-DD HH:mm:ss
func ParseDateToStr(date any, formatStr string) string {
t, ok := date.(time.Time)
if !ok {
switch v := date.(type) {
case int64:
if v == 0 {
return ""
}
t = time.UnixMilli(v)
case string:
parsedTime, err := time.Parse(formatStr, v)
if err != nil {
fmt.Printf("utils ParseDateToStr err %v \n", err)
return ""
}
t = parsedTime
default:
return ""
}
}
return t.Format(formatStr)
}
// 格式时间成日期路径
//
// 年/月 列如2022/12
func ParseDatePath(date time.Time) string {
return date.Format("2006/01")
}