formats

package
v0.21.16 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2021 License: GPL-3.0 Imports: 15 Imported by: 4

Documentation

Index

Constants

View Source
const (
	Date  = "2006-01-02"
	ZDate = "2006-1-2"

	Time     = "15:04:05"
	DashTime = Date + "-15-04-05"
	DateTime = Date + " " + Time

	ChineseDate      = "2006年01月02日"
	ChineseZDate     = "2006年1月2日"
	ChineseDateTime  = "2006年01月02日15时04分05秒"
	ChineseZDateTime = "2006年1月2日15时4分5秒"

	DefaultDateTime = "0001-01-01 00:00:00"
)

Datas

View Source
const (
	MonthLunarDays   int = 30
	MonthSolarDays   int = 31
	MonthFebLeapDays int = 29
	MonthFebDays     int = 28
)

MonthDays

View Source
const Hidden = "<hidden>"

Variables

View Source
var (
	// WeekStartDay 一周的开始时间
	WeekStartDay = time.Sunday
)

Functions

func BeginOfDay

func BeginOfDay() time.Time

BeginOfDay 当前日期的起始时间

func BeginOfDuration

func BeginOfDuration(d time.Duration) time.Time

BeginOfDuration 以当前的时间作为起始时间,抹掉一部分时间

func BeginOfMonth

func BeginOfMonth() time.Time

BeginOfMonth 当前月的起始时间

func BeginOfWeek

func BeginOfWeek() time.Time

BeginOfWeek 当前日期的起始时间

func BeginOfYear

func BeginOfYear() time.Time

BeginOfYear 当前年的起始时间

func EndOfDay

func EndOfDay() time.Time

EndOfDay 当前日期的终止时间

func EndOfMonth

func EndOfMonth() time.Time

EndOfMonth 当前月的终止时间

func EndOfWeek

func EndOfWeek() time.Time

EndOfWeek 当前日期的终止时间

func EndOfYear

func EndOfYear() time.Time

EndOfYear 当前年的终止时间

func FindStringSubmatchMap

func FindStringSubmatchMap(s, exp string) (map[string]string, bool)

FindStringSubmatchMap infomation: returns a map of strings holding the text of the leftmost match of the regular expression in s and the matches, if any, of its subexpressions, as defined by the 'Submatch' description in the package comment. A return value of nil indicates no match.

func FormatChineseDate

func FormatChineseDate(t time.Time) string

FormatChineseDate 格式化中国日期

func FormatChineseDateTime

func FormatChineseDateTime(t time.Time) string

FormatChineseDateTime 格式化中国日期时间

func FormatChineseZDate

func FormatChineseZDate(t time.Time) string

FormatChineseZDate 格式化中文缩写日期

func FormatChineseZDateTime

func FormatChineseZDateTime(t time.Time) string

FormatChineseZDateTime 格式化去0的中国日期时间

func FormatDashTime

func FormatDashTime(t time.Time) string

FormatDashTime format datetime string with dash

func FormatDate

func FormatDate(t time.Time) string

FormatDate 格式化日期

func FormatDateTime

func FormatDateTime(t time.Time) string

FormatDateTime format datetime string

func FormatHTTPGMT

func FormatHTTPGMT(t time.Time) string

FormatHTTPGMT format GMT string

func FormatLayoutTime

func FormatLayoutTime(t time.Time, layout string) string

FormatLayoutTime 格式化自定义的时间

func FormatRFC3339

func FormatRFC3339(t time.Time) string

FormatRFC3339 format RFC3339 string

func FormatRFC3339Nano

func FormatRFC3339Nano(t time.Time) string

FormatRFC3339Nano format RFC3339Nano string

func FormatTime

func FormatTime(t time.Time) string

FormatTime format time string

func FormatZDate

func FormatZDate(t time.Time) string

FormatZDate 格式化不含0的日期

func GbkToUtf8

func GbkToUtf8(s []byte) ([]byte, error)

GbkToUtf8 gbk to utf8

func GetMonthDays

func GetMonthDays(year, month int) int

GetMonthDays get year's month days

func GetTimeMonthDays

func GetTimeMonthDays(t time.Time) int

GetTimeMonthDays get time's month days

func HideString

func HideString(origin string, start, length int) string

HideString hide some words origin: the string to be hidden start: from 1 to len(origin), replace * from beginning length: replace origin length from the beginning

func IntToString

func IntToString(value interface{}) (string, error)

IntToString parse int to string

func IsZero

func IsZero(t time.Time) bool

IsZero judge time is zero

func ParseChineseDate

func ParseChineseDate(t string) (time.Time, error)

ParseChineseDate 转换中文日期格式为cacheLocation的时间

func ParseChineseDateTime

func ParseChineseDateTime(t string) (time.Time, error)

ParseChineseDateTime 转换中文时间格式为cacheLocation的时间

func ParseDate

func ParseDate(t string) (time.Time, error)

ParseDate 转换日期格式为cacheLocation的时间

func ParseDateTime

func ParseDateTime(t string) (time.Time, error)

ParseDateTime 转换时间格式为cacheLocation的时间

func ParseInLocation

func ParseInLocation(layout, timestring string, loc *time.Location) (time.Time, error)

ParseInLocation 解析时间

func ParseLayoutTime

func ParseLayoutTime(layout, timestring string) (time.Time, error)

ParseLayoutTime 解析时间

func ParseStringByteSize

func ParseStringByteSize(key string, defValue ...*big.Int) *big.Int

ParseStringByteSize return big size

func ParseStringTime

func ParseStringTime(s string, defValue ...time.Duration) time.Duration

ParseStringTime return time.Duration

func QuoteBytesToASCIIWithoutBackslashed

func QuoteBytesToASCIIWithoutBackslashed(bs []byte) string

QuoteBytesToASCIIWithoutBackslashed strconv.QuoteToASCII by bytes

func QuoteToASCIIWithoutBackslashed

func QuoteToASCIIWithoutBackslashed(s string) string

QuoteToASCIIWithoutBackslashed strconv.QuoteToASCII without Backslashed \\ import strconv

func RemoveDuplicateStringByMap

func RemoveDuplicateStringByMap(ss []string) []string

RemoveDuplicateStringByMap remove duplicate string by map whether a string is already exist.

func RoundFund

func RoundFund(fund float64) int64

RoundFund round fund to int64

func StringContainedInSlice

func StringContainedInSlice(needle string, haystack []string) bool

StringContainedInSlice a string contains a short string in haystack

func StringInSlice

func StringInSlice(needle string, haystack []string) bool

StringInSlice a string in haystack

func StringToDate

func StringToDate(t string) (time.Time, error)

StringToDate paser string to date, but is deprecated, use ParseDate

func StringToDateTime

func StringToDateTime(t string) (time.Time, error)

StringToDateTime parse string to datetime, but is deprecated, use ParseDateTime

func SuffixStringInSlice

func SuffixStringInSlice(needle string, haystack []string) bool

SuffixStringInSlice a string starts with a short string in haystack

func ToFloat64

func ToFloat64(value interface{}) (float64, error)

ToFloat64 covert any type to float64

func ToInt

func ToInt(value interface{}) (int, error)

ToInt parse value to int

func ToInt64

func ToInt64(value interface{}) (int64, error)

ToInt64 parse value to int64

func UnixToTime

func UnixToTime(unix int64) time.Time

UnixToTime parse unix to time

func Utf8ToGbk

func Utf8ToGbk(s []byte) ([]byte, error)

Utf8ToGbk utf8 to gbk

Types

type Config

type Config struct {
	WeekStartDay time.Weekday
	Location     *time.Location
}

Config configuration for now package

type Duration added in v0.21.8

type Duration time.Duration

func (Duration) MarshalYAML added in v0.21.8

func (d Duration) MarshalYAML() (interface{}, error)

MarshalYAML implements the yaml.Marshaler interface.

func (Duration) Seconds added in v0.21.15

func (d Duration) Seconds() int64

func (Duration) String added in v0.21.8

func (d Duration) String() string

func (*Duration) UnmarshalYAML added in v0.21.8

func (d *Duration) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

type Hide added in v0.21.15

type Hide string

func (Hide) MarshalJSON added in v0.21.15

func (s Hide) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for Hide.

func (Hide) MarshalYAML added in v0.21.15

func (s Hide) MarshalYAML() (interface{}, error)

MarshalYAML implements the yaml.Marshaler interface for Hide.

func (*Hide) UnmarshalYAML added in v0.21.15

func (s *Hide) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface for Hide.

type Int64s

type Int64s []int64

Int64s array int64

func (Int64s) Len

func (x Int64s) Len() int

func (Int64s) Less

func (x Int64s) Less(i, j int) bool

func (Int64s) Swap

func (x Int64s) Swap(i, j int)

type Ints

type Ints []int

Ints array int

func (Ints) Len

func (x Ints) Len() int

func (Ints) Less

func (x Ints) Less(i, j int) bool

func (Ints) Swap

func (x Ints) Swap(i, j int)

type Now

type Now struct {
	*time.Time
	Config
}

Now now time

func (*Now) BeginOfDay

func (p *Now) BeginOfDay() time.Time

BeginOfDay begin of day

func (*Now) BeginOfDuration

func (p *Now) BeginOfDuration(d time.Duration) time.Time

BeginOfDuration 获取当前时间,并抹掉一部分时间

func (*Now) BeginOfMonth

func (p *Now) BeginOfMonth() time.Time

BeginOfMonth begin of month

func (*Now) BeginOfWeek

func (p *Now) BeginOfWeek() time.Time

BeginOfWeek begin of week

func (*Now) BeginOfYear

func (p *Now) BeginOfYear() time.Time

BeginOfYear begin of year

func (*Now) EndOfDay

func (p *Now) EndOfDay() time.Time

EndOfDay end of day

func (*Now) EndOfMonth

func (p *Now) EndOfMonth() time.Time

EndOfMonth begin of month

func (*Now) EndOfWeek

func (p *Now) EndOfWeek() time.Time

EndOfWeek end of week

func (*Now) EndOfYear

func (p *Now) EndOfYear() time.Time

EndOfYear begin of year

func (*Now) Monday

func (p *Now) Monday() time.Time

Monday 周一的时间

func (*Now) Now

func (p *Now) Now() time.Time

Now 当前时间

func (*Now) ParseInLocation

func (*Now) ParseInLocation(layout, timestring string, loc *time.Location) (time.Time, error)

ParseInLocation 解析时间

func (*Now) ParseLayoutTime

func (p *Now) ParseLayoutTime(layout, s string) (time.Time, error)

ParseLayoutTime 解析时间

func (*Now) Sunday

func (p *Now) Sunday() time.Time

Sunday sunday

func (*Now) WithLocation

func (p *Now) WithLocation(loc *time.Location)

WithLocation 设置时区

type NowOption

type NowOption func(*Now)

NowOption 执行函数

func NowConfig

func NowConfig(cfg Config) NowOption

NowConfig 设置时间的配置

func NowLocation

func NowLocation(loc *time.Location) NowOption

NowLocation 设置时间Location

func NowTime

func NowTime(t *time.Time) NowOption

NowTime 获取当前时间

func NowWeekStartDay

func NowWeekStartDay(d time.Weekday) NowOption

NowWeekStartDay 设置一周开始时间

type Strings

type Strings []string

Strings array string

func (Strings) Len

func (x Strings) Len() int

func (Strings) Less

func (x Strings) Less(i, j int) bool

func (Strings) Swap

func (x Strings) Swap(i, j int)

type Times

type Times interface {
	Now() time.Time
	Monday() time.Time
	Sunday() time.Time
	BeginOfDay() time.Time
	EndOfDay() time.Time
	BeginOfWeek() time.Time
	EndOfWeek() time.Time
	BeginOfMonth() time.Time
	EndOfMonth() time.Time
	BeginOfYear() time.Time
	EndOfYear() time.Time
	BeginOfDuration(d time.Duration) time.Time
	ParseLayoutTime(layout, timestring string) (time.Time, error)
	ParseInLocation(layout, timestring string, loc *time.Location) (time.Time, error)
	WithLocation(loc *time.Location)
}

Times 时间处理函数

func GetNow

func GetNow(opts ...NowOption) Times

GetNow initialise by input time 初始化当前时间

func WithLocation

func WithLocation(loc *time.Location) Times

WithLocation 返回带自定义Location的时间

type Uint32s

type Uint32s []uint32

Uint32s array uint32

func (Uint32s) Len

func (x Uint32s) Len() int

func (Uint32s) Less

func (x Uint32s) Less(i, j int) bool

func (Uint32s) Swap

func (x Uint32s) Swap(i, j int)

type Uints

type Uints []uint

Uints array uint

func (Uints) Len

func (x Uints) Len() int

func (Uints) Less

func (x Uints) Less(i, j int) bool

func (Uints) Swap

func (x Uints) Swap(i, j int)

Jump to

Keyboard shortcuts

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