Documentation
¶
Index ¶
- Constants
- func GetAge(startTime int64) string
- func LocalToUTC(localtime time.Time, timezone string) (time.Time, error)
- func LocalToUTCString(localtime string, timezone string) (string, error)
- func MTServerTimeToUTC(mtServerTime int64) (int64, error)
- func UTCToLocal(utctime time.Time, timezone string) (time.Time, error)
- func UTCToLocalString(utctime string, timezone string) (string, error)
- func UTCToMTServerTime(utcTime int64) (int64, error)
- type Time
Constants ¶
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).
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 ¶
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
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
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
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
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
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
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
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
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
String returns the time formatted as a string using TIME_FORMAT.
func (*Time) UnmarshalJSON ¶ added in v0.1.37
UnmarshalJSON implements the json.Unmarshaler interface, parsing a quoted string in TIME_FORMAT into the Time value using the local timezone.