formats

package
v1.8.4 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2020 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

Variables

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

Functions

func BeginOfDay added in v1.3.0

func BeginOfDay() time.Time

BeginOfDay 当前日期的起始时间

func BeginOfDuration added in v1.3.0

func BeginOfDuration(d time.Duration) time.Time

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

func BeginOfMonth added in v1.3.0

func BeginOfMonth() time.Time

BeginOfMonth 当前月的起始时间

func BeginOfWeek added in v1.3.0

func BeginOfWeek() time.Time

BeginOfWeek 当前日期的起始时间

func BeginOfYear added in v1.3.0

func BeginOfYear() time.Time

BeginOfYear 当前年的起始时间

func EndOfDay added in v1.3.0

func EndOfDay() time.Time

EndOfDay 当前日期的终止时间

func EndOfMonth added in v1.3.0

func EndOfMonth() time.Time

EndOfMonth 当前月的终止时间

func EndOfWeek added in v1.3.0

func EndOfWeek() time.Time

EndOfWeek 当前日期的终止时间

func EndOfYear added in v1.3.0

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 added in v1.3.0

func FormatChineseDateTime(t time.Time) string

FormatChineseDateTime 格式化中国日期时间

func FormatChineseZDate

func FormatChineseZDate(t time.Time) string

FormatChineseZDate 格式化中文缩写日期

func FormatChineseZDateTime added in v1.3.0

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 added in v1.3.0

func FormatHTTPGMT(t time.Time) string

FormatHTTPGMT format GMT string

func FormatLayoutTime added in v1.3.0

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 added in v1.3.0

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

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

func ParseChineseDateTime added in v1.3.0

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

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

func ParseDate added in v1.3.0

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

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

func ParseDateTime added in v1.3.0

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

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

func ParseInLocation added in v1.3.0

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

ParseInLocation 解析时间

func ParseLayoutTime added in v1.3.0

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

ParseLayoutTime 解析时间

func ParseStringByteSize

func ParseStringByteSize(key string) *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 added in v1.8.0

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 added in v1.8.0

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

StringContainedInSlice a string contains a short string in haystack

func StringInSlice added in v1.8.0

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 added in v1.8.0

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 added in v1.3.0

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

Config configuration for now package

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 added in v1.3.0

type Now struct {
	*time.Time
	Config
}

Now now time

func (*Now) BeginOfDay added in v1.3.0

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

BeginOfDay begin of day

func (*Now) BeginOfDuration added in v1.3.0

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

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

func (*Now) BeginOfMonth added in v1.3.0

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

BeginOfMonth begin of month

func (*Now) BeginOfWeek added in v1.3.0

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

BeginOfWeek begin of week

func (*Now) BeginOfYear added in v1.3.0

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

BeginOfYear begin of year

func (*Now) EndOfDay added in v1.3.0

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

EndOfDay end of day

func (*Now) EndOfMonth added in v1.3.0

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

EndOfMonth begin of month

func (*Now) EndOfWeek added in v1.3.0

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

EndOfWeek end of week

func (*Now) EndOfYear added in v1.3.0

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

EndOfYear begin of year

func (*Now) Monday added in v1.3.0

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

Monday 周一的时间

func (*Now) Now added in v1.3.1

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

Now 当前时间

func (*Now) ParseInLocation added in v1.3.0

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

ParseInLocation 解析时间

func (*Now) ParseLayoutTime added in v1.3.0

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

ParseLayoutTime 解析时间

func (*Now) Sunday added in v1.3.0

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

Sunday sunday

func (*Now) WithLocation added in v1.3.0

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

WithLocation 设置时区

type NowOption added in v1.3.0

type NowOption func(*Now)

NowOption 执行函数

func NowConfig added in v1.3.0

func NowConfig(cfg Config) NowOption

NowConfig 设置时间的配置

func NowLocation added in v1.3.0

func NowLocation(loc *time.Location) NowOption

NowLocation 设置时间Location

func NowTime added in v1.3.0

func NowTime(t *time.Time) NowOption

NowTime 获取当前时间

func NowWeekStartDay added in v1.3.0

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 added in v1.3.0

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 added in v1.3.0

func GetNow(opts ...NowOption) Times

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

func WithLocation added in v1.3.1

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