moment

package
v0.11.14 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2024 License: Apache-2.0 Imports: 6 Imported by: 1

Documentation

Overview

* @Author: kamalyes 501893067@qq.com * @Date: 2023-07-28 00:50:58 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2024-11-20 18:55:55 * @FilePath: \go-toolbox\pkg\moment\base.go * @Description: * * Copyright (c) 2024 by kamalyes, All Rights Reserved.

* @Author: kamalyes 501893067@qq.com * @Date: 2023-07-28 00:50:58 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2024-11-10 18:55:05 * @FilePath: \go-toolbox\pkg\moment\constants.go * @Description: * * Copyright (c) 2024 by kamalyes, All Rights Reserved.

* @Author: kamalyes 501893067@qq.com * @Date: 2023-07-28 00:50:58 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2024-10-17 15:56:55 * @FilePath: \go-toolbox\pkg\moment\date.go * @Description: * * Copyright (c) 2024 by kamalyes, All Rights Reserved.

* @Author: kamalyes 501893067@qq.com * @Date: 2023-07-28 00:50:58 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2024-11-01 02:01:27 * @FilePath: \go-toolbox\pkg\moment\time.go * @Description: * * Copyright (c) 2024 by kamalyes, All Rights Reserved.

Index

Constants

View Source
const (
	// 默认时区
	DefaultTimezone = "Asia/Shanghai"

	// Nanosecond 纳秒,作为最基础的单位
	Nanosecond time.Duration = 1

	// Microsecond 微妙,表示1微妙持续的纳秒时长
	Microsecond = 1000 * Nanosecond

	// Millisecond 毫秒,表示1毫秒持续的纳秒时长
	Millisecond = 1000 * Microsecond

	// Second 秒,表示1秒持续的纳秒时长
	Second = 1000 * Millisecond

	// Minute 分钟,表示1分钟持续的纳秒时长
	Minute = 60 * Second

	// Hour 小时,表示1小时持续的纳秒时长
	Hour = 60 * Minute

	// Day 天,表示1天持续的纳秒时长
	// 这里不考虑夏时制问题,泛指国际基础单位制(民用日)所理解的时间
	Day = 24 * Hour

	// Week 周, 表示1周持续的纳秒时长
	// 这里不考虑夏时制问题,泛指国际基础单位制(民用日)所理解的时间
	Week = 7 * Day

	// Year 年,表示1年持续的纳秒时长
	Year = 365 * Day
)

通用的时间单位持续时长,这里泛指国际基础单位制(民用日)所理解的时间,不考虑夏时制,不用作科学与天文学 例如 一天 24小时,一周 168小时,7天

Variables

This section is empty.

Functions

func CalculateAge added in v0.11.11

func CalculateAge(birthday string, currentTime time.Time) (int, error)

计算年龄的函数,currentTime 为计算年龄时的参考时间

func CharToCode

func CharToCode(layout string) string

func ConvertStringToTimestamp

func ConvertStringToTimestamp(dateString, layout string, timeZone string) (int64, error)

ConvertStringToTimestamp String时间类型转换为时间戳

func CurrentGmtTime

func CurrentGmtTime() string

GMT TIME

func CurrentMicrosecond

func CurrentMicrosecond() int64

微秒

func CurrentMillisecond

func CurrentMillisecond() int64

毫秒

func CurrentNanosecond

func CurrentNanosecond() int64

纳秒

func FormatWithLocation

func FormatWithLocation(timezone string, ts int64, defaultDateFormat string) string

FormatWithLocation 国际化时间戳转换字符串

func GetCurrentTimeInfo

func GetCurrentTimeInfo() (string, int, time.Time)

GetCurrentTimeInfo 获取当前日期、小时和时间的通用函数

func GetServerTimezone

func GetServerTimezone() string

GetServerTimezone 获取服务器的本地时区信息

func GetTimeOffset

func GetTimeOffset(timezone string, ts int64) (offset int)

GetTimeOffset 国际化时间戳偏移

func LocalTime

func LocalTime() string

本地时区(年-月-日 时:分:秒)

func ParseDay

func ParseDay(t ...time.Time) int

func ParseHour

func ParseHour(t ...time.Time) int

获取小时

func ParseMinute

func ParseMinute(t ...time.Time) int

获取分钟

func ParseMonth

func ParseMonth(t ...time.Time) int

func ParseSecond

func ParseSecond(t ...time.Time) int

获取秒

func ParseString

func ParseString(f ...string) string

timestamp

func ParseTimestamp

func ParseTimestamp(args ...string) int64

字符串转时间戳

func ParseWithLocation

func ParseWithLocation(timezone string, timeStr string, defaultDateFormat string) int64

ParseWithLocation 国际化时间字符串转换时间戳

func ParseYear

func ParseYear(t ...time.Time) int

func ParseYearDay

func ParseYearDay(t ...time.Time) int

func SafeParseTimeToUnixNano

func SafeParseTimeToUnixNano(timeStr string) int64

SafeParseTimeToUnixNano

func StrtoTime

func StrtoTime(s string, args ...string) (time.Time, error)

String To time.Time

Types

type TimeDifference

type TimeDifference struct {
	Years   int
	Days    int
	Hours   int
	Minutes int
	Seconds int
}

TimeDifference 结构体用于存储年、天、小时、分钟和秒

func CalculateTimeDifference

func CalculateTimeDifference(duration time.Duration) TimeDifference

CalculateTimeDifference 计算给定的 time.Duration,并返回 TimeDifference

Jump to

Keyboard shortcuts

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