- jd afs api

This commit is contained in:
gazebo
2019-05-06 15:51:19 +08:00
parent 2e0b9206b8
commit 3668b8cf89
4 changed files with 234 additions and 6 deletions

44
utils/java_date.go Normal file
View 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)
}