datetime

package
v0.1.37 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 16, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const MTSEVER_TIME_OFFSET = 25200 // 7(hours)*3600 seconds

MTSEVER_TIME_OFFSET is the MT server time offset in seconds relative to New York Time (7 hours * 3600 seconds).

View Source
const TIME_FORMAT = "2006-01-02 15:04:05"

TIME_FORMAT is the standard datetime layout used throughout this package ("2006-01-02 15:04:05").

Variables

This section is empty.

Functions

func GetAge

func GetAge(startTime int64) string

GetAge returns a human-readable duration string representing the elapsed time since the given Unix timestamp (in seconds), formatted as "Xd Xh Xm Xs".

func LocalToUTC added in v0.1.37

func LocalToUTC(localtime time.Time, timezone string) (time.Time, error)

LocalToUTC converts a local time.Time value from the specified timezone to UTC. Usage: 1, format timezone to local time; 2, call UTC to the localtime with timezone.

func LocalToUTCString added in v0.1.37

func LocalToUTCString(localtime string, timezone string) (string, error)

LocalToUTCString converts a local time string (formatted with TIME_FORMAT) in the specified timezone to a UTC time string. It returns the formatted UTC time string or an error.

func MTServerTimeToUTC added in v0.1.37

func MTServerTimeToUTC(mtServerTime int64) (int64, error)

MTServerTimeToUTC converts MTServerTime to UTC time MTServerTime --> MTServerTime - 2/3*3600(2/3*3600 = 7*3600 - New York timezone offset) --> UTC EST: UTC-5, New York timezone offset = -18000s; EDT: UTC-4, New York timezone offset = -14400s

func UTCToLocal added in v0.1.37

func UTCToLocal(utctime time.Time, timezone string) (time.Time, error)

UTCToLocal converts a UTC time.Time value to the specified timezone (e.g. "Asia/Shanghai") and returns the equivalent local time. Usage: 1, get UTC with time.Now().UTC(); 2, call In to the UTC time.

func UTCToLocalString added in v0.1.37

func UTCToLocalString(utctime string, timezone string) (string, error)

UTCToLocalString converts a UTC time string (formatted with TIME_FORMAT) to a local time string in the specified timezone. It returns the formatted local time string or an error.

func UTCToMTServerTime added in v0.1.37

func UTCToMTServerTime(utcTime int64) (int64, error)

UTCToMTServerTime converts UTC time to MTServerTime UTC --> UTC time + 2/3*3600(2/3*3600 = 7*3600 - New York timezone offset) -> MTServerTime EST: UTC-5, New York timezone offset = -18000s; EDT: UTC-4, New York timezone offset = -14400s

Types

type Time added in v0.1.37

type Time time.Time

Time is a custom time type that wraps the standard library time.Time and provides JSON marshaling/unmarshaling using the TIME_FORMAT layout.

func (Time) MarshalJSON added in v0.1.37

func (t Time) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface, encoding the time value as a quoted string using TIME_FORMAT.

func (Time) String added in v0.1.37

func (t Time) String() string

String returns the time formatted as a string using TIME_FORMAT.

func (*Time) UnmarshalJSON added in v0.1.37

func (t *Time) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements the json.Unmarshaler interface, parsing a quoted string in TIME_FORMAT into the Time value using the local timezone.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL