Compare commits
3 Commits
entgo/v1.1
...
v1.1.26
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3ec9bbbd27 | ||
|
|
faa5817857 | ||
|
|
89a69a9d4d |
2
tag.bat
2
tag.bat
@@ -1,4 +1,4 @@
|
||||
git tag v1.1.24
|
||||
git tag v1.1.26
|
||||
|
||||
git tag bank_card/v1.1.5
|
||||
git tag geoip/v1.1.5
|
||||
|
||||
@@ -217,7 +217,7 @@ func timeMarshalJSON(t time.Time, layout string) ([]byte, error) {
|
||||
}
|
||||
|
||||
func ParseSlice(layout string, strings []string) ([]time.Time, error) {
|
||||
times := []time.Time{}
|
||||
var times []time.Time
|
||||
for _, raw := range strings {
|
||||
t, err := time.Parse(layout, raw)
|
||||
if err != nil {
|
||||
|
||||
@@ -33,10 +33,7 @@ func UnixMilliToStringPtr(milli *int64) *string {
|
||||
|
||||
tm := time.UnixMilli(*milli)
|
||||
|
||||
// 设置默认时区
|
||||
tm.In(GetDefaultTimeLocation())
|
||||
|
||||
str := tm.Format(TimeLayout)
|
||||
str := tm.In(GetDefaultTimeLocation()).Format(TimeLayout)
|
||||
return &str
|
||||
}
|
||||
|
||||
@@ -133,10 +130,7 @@ func TimeToTimeString(tm *time.Time) *string {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 设置默认时区
|
||||
tm.In(GetDefaultTimeLocation())
|
||||
|
||||
return trans.String(tm.Format(TimeLayout))
|
||||
return trans.String(tm.In(GetDefaultTimeLocation()).Format(TimeLayout))
|
||||
}
|
||||
|
||||
// StringDateToTime 字符串 -> 时间
|
||||
@@ -175,10 +169,15 @@ func TimeToDateString(tm *time.Time) *string {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 设置默认时区
|
||||
tm.In(GetDefaultTimeLocation())
|
||||
return trans.String(tm.In(GetDefaultTimeLocation()).Format(DateLayout))
|
||||
}
|
||||
|
||||
return trans.String(tm.Format(DateLayout))
|
||||
func TimeToString(tm *time.Time, layout string) *string {
|
||||
if tm == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return trans.String(tm.Format(layout))
|
||||
}
|
||||
|
||||
// TimestamppbToTime timestamppb.Timestamp -> time.Time
|
||||
|
||||
@@ -149,6 +149,15 @@ func TestTimeToDateString(t *testing.T) {
|
||||
assert.Nil(t, result)
|
||||
}
|
||||
|
||||
func TestTimeToString(t *testing.T) {
|
||||
now := time.Now()
|
||||
|
||||
fmt.Println(*TimeToString(&now, DateLayout))
|
||||
fmt.Println(*TimeToString(&now, ISO8601))
|
||||
fmt.Println(*TimeToString(&now, ISO8601TZHour))
|
||||
fmt.Println(*TimeToString(&now, ISO8601NoTZ))
|
||||
}
|
||||
|
||||
func TestTimestamppbToTime(t *testing.T) {
|
||||
// 测试有效输入
|
||||
timestamp := timestamppb.Now()
|
||||
|
||||
Reference in New Issue
Block a user