12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- package common
- import (
- "fmt"
- "strconv"
- "strings"
- "time"
- )
- // NowTime 时间格式化
- //func NowTime() string {
- // return time.Now().Format(`2006-01-02 15:04:05`)
- //}
- func NowTime(format string) string {
- return time.Now().Format(format)
- }
- // GetHexTimeStr 时间16进制字符串
- func GetHexTimeStr() string {
- nowtime := time.Now().Format(`2006-01-02 15:04:05`)
- nowtime = "2023-07-31 14:28:00"
- nowtime = nowtime[2:]
- split := strings.Split(nowtime, " ")
- yearArr := strings.Split(split[0], "-")
- timeArr := strings.Split(split[1], ":")
- var result strings.Builder
- for _, value := range yearArr {
- valueInt, err := strconv.ParseInt(value, 10, 64)
- if err != nil {
- fmt.Errorf("%s", "data format error")
- return ""
- }
- formatInt := strconv.FormatInt(valueInt, 16)
- if len(formatInt) == 1 {
- formatInt = fmt.Sprintf("%s%s", "0", formatInt)
- }
- result.WriteString(formatInt)
- }
- for _, value := range timeArr {
- valueInt, err := strconv.ParseInt(value, 10, 64)
- if err != nil {
- fmt.Errorf("%s", "data format error")
- return ""
- }
- formatInt := strconv.FormatInt(valueInt, 16)
- if len(formatInt) == 1 {
- formatInt = fmt.Sprintf("%s%s", "0", formatInt)
- }
- result.WriteString(formatInt)
- }
- //for _, value := range timeArr {
- // valueInt, err := strconv.ParseInt(value, 10, 64)
- // if err != nil {
- // fmt.Errorf("%s", "data format error")
- // return ""
- // }
- // if valueInt < 10 {
- // result.WriteString("0")
- // }
- // result.WriteString(strconv.FormatInt(valueInt, 16))
- //}
- return result.String()
- }
|