Home > Software design >  How to convert seconds beginning from 1904 to datetime in golang?
How to convert seconds beginning from 1904 to datetime in golang?

Time:04-24

Go has a time.Unix function which converts seconds to datetime.

Unix returns the local Time corresponding to the given Unix time, sec seconds and nsec nanoseconds since January 1, 1970 UTC.

Is there a function which can convert seconds from 1904?

Basically in need to convert seconds beginning from 1904 3400769156 to datetime.

CodePudding user response:

No existing function, but creating one yourself isn't that hard:

func since1904ToTime(sec int64) time.Time {
    return time.Date(1904, time.January, 1, 0, 0, 0, 0, time.Local).Add(time.Second*time.Duration(sec))
}
  • Related