mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-04 12:52:28 +08:00
fix: format timezone issue
This commit is contained in:
@@ -46,15 +46,15 @@ func (t *theTime) ToUnix() int64 {
|
||||
|
||||
// ToFormat return the time string 'yyyy-mm-dd hh:mm:ss' of unix time
|
||||
func (t *theTime) ToFormat() string {
|
||||
return time.Unix(t.unix, 0).Local().Format("2006-01-02 15:04:05")
|
||||
return time.Unix(t.unix, 0).Format("2006-01-02 15:04:05")
|
||||
}
|
||||
|
||||
// ToFormatForTpl return the time string which format is specified tpl
|
||||
func (t *theTime) ToFormatForTpl(tpl string) string {
|
||||
return time.Unix(t.unix, 0).Local().Format(tpl)
|
||||
return time.Unix(t.unix, 0).Format(tpl)
|
||||
}
|
||||
|
||||
// ToFormatForTpl return iso8601 time string
|
||||
func (t *theTime) ToIso8601() string {
|
||||
return time.Unix(t.unix, 0).Local().Format(time.RFC3339)
|
||||
return time.Unix(t.unix, 0).Format(time.RFC3339)
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package datetime
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/duke-git/lancet/v2/internal"
|
||||
)
|
||||
@@ -25,8 +26,19 @@ func TestToFormat(t *testing.T) {
|
||||
tm1, err = NewFormat("2022-03-18 17:04:05")
|
||||
assert.IsNil(err)
|
||||
|
||||
res := tm1.ToFormat()
|
||||
assert.Equal("2022-03-18 17:04:05", res)
|
||||
// res := tm1.ToFormat()
|
||||
t1, err1 := time.Parse("2006-01-02 15:04:05", tm1.ToFormat())
|
||||
if err1 != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
t2, err2 := time.Parse("2006-01-02 15:04:05", "2022-03-18 17:04:05")
|
||||
if err2 != nil {
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
assert.Equal(t2, t1)
|
||||
// assert.Equal("2022-03-18 17:04:05", res)
|
||||
}
|
||||
|
||||
func TestToFormatForTpl(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user