Skip to content

Commit

Permalink
✨ feat: add From method
Browse files Browse the repository at this point in the history
  • Loading branch information
jingyuexing committed Oct 14, 2024
1 parent d0398ec commit 228d4c3
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions datetime.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,24 @@ type DateTime struct {
}

func NewDateTime() DateTime {
d := DateTime{
time: time.Now(),
DateFormat: "YYYY-MM-DD",
TimeFormat: "HH:mm:ss.ms",
}
d.Year = d.time.Year()
d.Month = int(d.time.Month())
d.Date = d.time.Day()
d.Day = d.time.Day()
d.Hour = d.time.Hour()
d.Minute = d.time.Minute()
d.Second = d.time.Second()
d.Nanosecond = d.time.Nanosecond()
return d
return From(time.Now())
}

func From(time time.Time) DateTime {
d := DateTime{
time: time,
DateFormat: "YYYY-MM-DD",
TimeFormat: "HH:mm:ss.ms",
}
d.Year = d.time.Year()
d.Month = int(d.time.Month())
d.Date = d.time.Day()
d.Day = d.time.Day()
d.Hour = d.time.Hour()
d.Minute = d.time.Minute()
d.Second = d.time.Second()
d.Nanosecond = d.time.Nanosecond()
return d
}

func (dt DateTime) SetYear(year int, month int, day int, hour int, minute int, second int, nanosecond int) DateTime {
Expand Down

0 comments on commit 228d4c3

Please sign in to comment.