times

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package times provides time formatting and timezone utilities.

It includes functions for formatting timestamps and calculating UTC offsets for local time zones.

Index

Constants

This section is empty.

Variables

View Source
var UTCOffset int64 = 28800000000

Functions

func FixedTs

func FixedTs(time time.Time) types.IntCount

FixedTs is a convenience function that adjusts the provided time.Time to a fixed timestamp by subtracting the predefined UTC offset (UTCOffset). Similar to FixedTsByLocation, this function addresses the issue of GORM returning time.Time values in UTC, which may not be correctly converted to local time zone strings by some database drivers. This version uses a predefined UTC offset, assuming the caller knows the required offset.

func FixedTsByLocation

func FixedTsByLocation(location *time.Location, time time.Time) types.IntCount

FixedTsByLocation adjusts the provided time.Time to a fixed timestamp by subtracting the microseconds offset of the given location from the Unix microsecond timestamp. This function is necessary because GORM returns all time.Time values in UTC, and this adjustment allows for converting them to the correct local time zone string, especially for database drivers that do not handle timezone conversions automatically.

func FormatTimestamp

func FormatTimestamp(timestamp int64, format string) string

FormatTimestamp 将Unix时间戳格式化为指定的UTC时间字符串, 单位: ms

func FormatTs

func FormatTs(ts int64) string

func FormatTsByLayout

func FormatTsByLayout(ts int64, layout string) string

Types

This section is empty.

Jump to

Keyboard shortcuts

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