- jd afs api
This commit is contained in:
44
utils/java_date.go
Normal file
44
utils/java_date.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type JavaDate struct {
|
||||
Day time.Weekday `json:"day"` // day of the week
|
||||
|
||||
Hours int `json:"hours"`
|
||||
Minutes int `json:"minutes"`
|
||||
Seconds int `json:"seconds"`
|
||||
Time int64 `json:"time"`
|
||||
TimezoneOffset int `json:"timezoneOffset"`
|
||||
|
||||
Date int `json:"date"`
|
||||
Month time.Month `json:"month"`
|
||||
Year int `json:"year"`
|
||||
}
|
||||
|
||||
func NewJavaDate() *JavaDate {
|
||||
return NewJavaDateFromTime(time.Now())
|
||||
}
|
||||
|
||||
func NewJavaDateFromTime(tm time.Time) (jd *JavaDate) {
|
||||
jd = &JavaDate{
|
||||
Time: tm.UnixNano() / 1000000,
|
||||
Day: tm.Weekday(),
|
||||
Hours: tm.Hour(),
|
||||
Minutes: tm.Minute(),
|
||||
Seconds: tm.Second(),
|
||||
}
|
||||
jd.Year, jd.Month, jd.Date = tm.Date()
|
||||
jd.Year -= 1900
|
||||
jd.Month--
|
||||
_, jd.TimezoneOffset = tm.Zone()
|
||||
jd.TimezoneOffset /= 60
|
||||
jd.TimezoneOffset = -jd.TimezoneOffset
|
||||
return jd
|
||||
}
|
||||
|
||||
func (j *JavaDate) GoTime() time.Time {
|
||||
return Timestamp2Time(j.Time / 1000)
|
||||
}
|
||||
Reference in New Issue
Block a user