mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-23 02:48:34 +08:00
[feat]网关子设备,直接上传,自动创建设备模型,无需手动创建
This commit is contained in:
@@ -2,7 +2,9 @@ package tool
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"pandax/pkg/global"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// SnakeString snake string, XxYy to xx_yy , XxYY to xx_y_y
|
||||
@@ -100,3 +102,26 @@ func StringToStruct(m string, s interface{}) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func TimeToFormat(val interface{}) string {
|
||||
switch v := val.(type) {
|
||||
case int64:
|
||||
// 如果是时间戳类型,将其转换为时间对象
|
||||
t := time.Unix(v, 0)
|
||||
// 格式化时间字符串
|
||||
formattedTime := t.Format("2006-01-02 15:04:05")
|
||||
return formattedTime
|
||||
case string:
|
||||
// 如果是字符串类型,将其解析为时间对象
|
||||
t, err := time.Parse("2006-01-02 15:04:05", v)
|
||||
if err != nil {
|
||||
global.Log.Error("时间格式非标准格式")
|
||||
return ""
|
||||
}
|
||||
// 格式化时间字符串
|
||||
formattedTime := t.Format("2006-01-02 15:04:05")
|
||||
return formattedTime
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user