carbon

package
v1.13.4 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2023 License: MIT Imports: 5 Imported by: 31

Documentation

Index

Constants

View Source
const (
	Local = carbon.Local // 本地时间
	UTC   = carbon.UTC   // 世界协调时间
	GMT   = carbon.GMT   // 格林尼治标准时间
	EET   = carbon.EET   // 欧洲东部标准时间
	WET   = carbon.WET   // 欧洲西部标准时间
	CET   = carbon.CET   // 欧洲中部标准时间
	EST   = carbon.EST   // 美国东部标准时间
	MST   = carbon.MST   // 美国山地标准时间

	Cuba      = carbon.Cuba      // 古巴
	Egypt     = carbon.Egypt     // 埃及
	Eire      = carbon.Eire      // 爱尔兰
	Greenwich = carbon.Greenwich // 格林尼治
	Iceland   = carbon.Iceland   // 冰岛
	Iran      = carbon.Iran      // 伊朗
	Israel    = carbon.Israel    // 以色列
	Jamaica   = carbon.Jamaica   // 牙买加
	Japan     = carbon.Japan     // 日本
	Libya     = carbon.Libya     // 利比亚
	Poland    = carbon.Poland    // 波兰
	Portugal  = carbon.Portugal  // 葡萄牙
	PRC       = carbon.PRC       // 中国
	Singapore = carbon.Singapore // 新加坡
	Turkey    = carbon.Turkey    // 土耳其

	Shanghai   = carbon.Shanghai   // 上海
	Chongqing  = carbon.Chongqing  // 重庆
	Harbin     = carbon.Harbin     // 哈尔滨
	Urumqi     = carbon.Urumqi     // 乌鲁木齐
	HongKong   = carbon.HongKong   // 香港
	Macao      = carbon.Macao      // 澳门
	Taipei     = carbon.Taipei     // 台北
	Tokyo      = carbon.Tokyo      // 东京
	Saigon     = carbon.Saigon     // 西贡
	Seoul      = carbon.Seoul      // 首尔
	Bangkok    = carbon.Bangkok    // 曼谷
	Dubai      = carbon.Dubai      // 迪拜
	NewYork    = carbon.NewYork    // 纽约
	LosAngeles = carbon.LosAngeles // 洛杉矶
	Chicago    = carbon.Chicago    // 芝加哥
	Moscow     = carbon.Moscow     // 莫斯科
	London     = carbon.London     // 伦敦
	Berlin     = carbon.Berlin     // 柏林
	Paris      = carbon.Paris      // 巴黎
	Rome       = carbon.Rome       // 罗马
	Sydney     = carbon.Sydney     // 悉尼
	Melbourne  = carbon.Melbourne  // 墨尔本
	Darwin     = carbon.Darwin     // 达尔文
)

timezone constants 时区常量

View Source
const (
	January   = carbon.January   // 一月
	February  = carbon.February  // 二月
	March     = carbon.March     // 三月
	April     = carbon.April     // 四月
	May       = carbon.May       // 五月
	June      = carbon.June      // 六月
	July      = carbon.July      // 七月
	August    = carbon.August    // 八月
	September = carbon.September // 九月
	October   = carbon.October   // 十月
	November  = carbon.November  // 十一月
	December  = carbon.December  // 十二月
)

month constants 月份常量

View Source
const (
	Monday    = carbon.Monday    // 周一
	Tuesday   = carbon.Tuesday   // 周二
	Wednesday = carbon.Wednesday // 周三
	Thursday  = carbon.Thursday  // 周四
	Friday    = carbon.Friday    // 周五
	Saturday  = carbon.Saturday  // 周六
	Sunday    = carbon.Sunday    // 周日
)

week constants 星期常量

View Source
const (
	YearsPerMillennium = 1000 // 每千年1000年
	YearsPerCentury    = 100  // 每世纪100年
	YearsPerDecade     = 10   // 每十年10年
	QuartersPerYear    = 4    // 每年4个季度
	MonthsPerYear      = 12   // 每年12月
	MonthsPerQuarter   = 3    // 每季度3月
	WeeksPerNormalYear = 52   // 每常规年52周

	WeeksPerMonth     = 4      // 每月4周
	DaysPerLeapYear   = 366    // 每闰年366天
	DaysPerNormalYear = 365    // 每常规年365天
	DaysPerWeek       = 7      // 每周7天
	HoursPerWeek      = 168    // 每周168小时
	HoursPerDay       = 24     // 每天24小时
	MinutesPerDay     = 1440   // 每天1440分钟
	MinutesPerHour    = 60     // 每小时60分钟
	SecondsPerWeek    = 604800 // 每周604800秒
	SecondsPerDay     = 86400  // 每天86400秒
	SecondsPerHour    = 3600   // 每小时3600秒
	SecondsPerMinute  = 60     // 每分钟60秒
)

number constants 数字常量

View Source
const (
	ANSICLayout              = stdtime.ANSIC
	UnixDateLayout           = stdtime.UnixDate
	RubyDateLayout           = stdtime.RubyDate
	RFC822Layout             = stdtime.RFC822
	RFC822ZLayout            = stdtime.RFC822Z
	RFC850Layout             = stdtime.RFC850
	RFC1123Layout            = stdtime.RFC1123
	RFC1123ZLayout           = stdtime.RFC1123Z
	RssLayout                = stdtime.RFC1123Z
	KitchenLayout            = stdtime.Kitchen
	RFC2822Layout            = stdtime.RFC1123Z
	CookieLayout             = carbon.CookieLayout
	RFC3339Layout            = carbon.RFC3339Layout
	RFC3339MilliLayout       = carbon.RFC3339MilliLayout
	RFC3339MicroLayout       = carbon.RFC3339MicroLayout
	RFC3339NanoLayout        = carbon.RFC3339NanoLayout
	ISO8601Layout            = carbon.ISO8601Layout
	ISO8601MilliLayout       = carbon.ISO8601MilliLayout
	ISO8601MicroLayout       = carbon.ISO8601MicroLayout
	ISO8601NanoLayout        = carbon.ISO8601NanoLayout
	RFC1036Layout            = carbon.RFC1036Layout
	RFC7231Layout            = carbon.RFC7231Layout
	DayDateTimeLayout        = carbon.DayDateTimeLayout
	DateTimeLayout           = carbon.DateTimeLayout
	DateTimeMilliLayout      = carbon.DateTimeMilliLayout
	DateTimeMicroLayout      = carbon.DateTimeMicroLayout
	DateTimeNanoLayout       = carbon.DateTimeNanoLayout
	ShortDateTimeLayout      = carbon.ShortDateTimeLayout
	ShortDateTimeMilliLayout = carbon.ShortDateTimeMilliLayout
	ShortDateTimeMicroLayout = carbon.ShortDateTimeMicroLayout
	ShortDateTimeNanoLayout  = carbon.ShortDateTimeNanoLayout
	DateLayout               = carbon.DateLayout
	DateMilliLayout          = carbon.DateMilliLayout
	DateMicroLayout          = carbon.DateMicroLayout
	DateNanoLayout           = carbon.DateNanoLayout
	ShortDateLayout          = carbon.ShortDateLayout
	ShortDateMilliLayout     = carbon.ShortDateMilliLayout
	ShortDateMicroLayout     = carbon.ShortDateMicroLayout
	ShortDateNanoLayout      = carbon.ShortDateNanoLayout
	TimeLayout               = carbon.TimeLayout
	TimeMilliLayout          = carbon.TimeMilliLayout
	TimeMicroLayout          = carbon.TimeMicroLayout
	TimeNanoLayout           = carbon.TimeNanoLayout
	ShortTimeLayout          = carbon.ShortTimeLayout
	ShortTimeMilliLayout     = carbon.ShortTimeMilliLayout
	ShortTimeMicroLayout     = carbon.ShortTimeMicroLayout
	ShortTimeNanoLayout      = carbon.ShortTimeNanoLayout
)

layout constants 布局模板常量

Variables

This section is empty.

Functions

func IsTestNow

func IsTestNow() bool

IsTestNow Determine if the test now time is set.

func SetTestNow

func SetTestNow(testTime Carbon)

SetTestNow Set the test time. Remember to unset after used.

func SetTimezone

func SetTimezone(timezone string)

SetTimezone sets timezone. 设置时区

func UnsetTestNow

func UnsetTestNow()

UnsetTestNow Unset the test time.

Types

type Carbon

type Carbon = carbon.Carbon

func FromDate

func FromDate(year int, month int, day int, timezone ...string) Carbon

FromDate return a Carbon object of given date.

func FromDateMicro

func FromDateMicro(year int, month int, day int, microsecond int, timezone ...string) Carbon

FromDateMicro return a Carbon object of given microsecond date.

func FromDateMilli

func FromDateMilli(year int, month int, day int, millisecond int, timezone ...string) Carbon

FromDateMilli return a Carbon object of given millisecond date.

func FromDateNano

func FromDateNano(year int, month int, day int, nanosecond int, timezone ...string) Carbon

FromDateNano return a Carbon object of given nanosecond date.

func FromDateTime

func FromDateTime(year int, month int, day int, hour int, minute int, second int, timezone ...string) Carbon

FromDateTime return a Carbon object of given date and time.

func FromDateTimeMicro

func FromDateTimeMicro(year int, month int, day int, hour int, minute int, second int, microsecond int, timezone ...string) Carbon

FromDateTimeMicro return a Carbon object of given date and microsecond time.

func FromDateTimeMilli

func FromDateTimeMilli(year int, month int, day int, hour int, minute int, second int, millisecond int, timezone ...string) Carbon

FromDateTimeMilli return a Carbon object of given date and millisecond time.

func FromDateTimeNano

func FromDateTimeNano(year int, month int, day int, hour int, minute int, second int, nanosecond int, timezone ...string) Carbon

FromDateTimeNano return a Carbon object of given date and nanosecond time.

func FromStdTime

func FromStdTime(time stdtime.Time) Carbon

FromStdTime return a Carbon object of given time.Time object.

func FromTime

func FromTime(hour int, minute int, second int, timezone ...string) Carbon

FromTime return a Carbon object of given time.

func FromTimeMicro

func FromTimeMicro(hour int, minute int, second int, microsecond int, timezone ...string) Carbon

FromTimeMicro return a Carbon object of given microsecond time.

func FromTimeMilli

func FromTimeMilli(hour int, minute int, second int, millisecond int, timezone ...string) Carbon

FromTimeMilli return a Carbon object of given millisecond time.

func FromTimeNano

func FromTimeNano(hour int, minute int, second int, nanosecond int, timezone ...string) Carbon

FromTimeNano return a Carbon object of given nanosecond time.

func FromTimestamp

func FromTimestamp(timestamp int64, timezone ...string) Carbon

FromTimestamp return a Carbon object of given timestamp.

func FromTimestampMicro

func FromTimestampMicro(timestamp int64, timezone ...string) Carbon

FromTimestampMicro return a Carbon object of given microsecond timestamp.

func FromTimestampMilli

func FromTimestampMilli(timestamp int64, timezone ...string) Carbon

FromTimestampMilli return a Carbon object of given millisecond timestamp.

func FromTimestampNano

func FromTimestampNano(timestamp int64, timezone ...string) Carbon

FromTimestampNano return a Carbon object of given nanosecond timestamp.

func Now

func Now(timezone ...string) Carbon

Now return a Carbon object of now.

func Parse

func Parse(value string, timezone ...string) Carbon

Parse return a Carbon object of given value.

func ParseByFormat

func ParseByFormat(value, format string, timezone ...string) Carbon

ParseByFormat return a Carbon object of given value and format.

func ParseByLayout

func ParseByLayout(value, layout string, timezone ...string) Carbon

ParseByLayout return a Carbon object of given value and layout.

type Clock

type Clock struct {
	// contains filtered or unexported fields
}

type Date

type Date struct {
	Carbon
}

Date defines a Date struct. 定义 Date 结构体

func NewDate

func NewDate(carbon Carbon) Date

func (Date) GormDataType added in v1.13.1

func (t Date) GormDataType() string

func (Date) MarshalJSON

func (t Date) MarshalJSON() ([]byte, error)

MarshalJSON implements the interface json.Marshal for Date struct. 实现 MarshalJSON 接口

func (Date) String

func (t Date) String() string

String implements the interface Stringer for Date struct. 实现 Stringer 接口

func (*Date) UnmarshalJSON

func (t *Date) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the interface json.Unmarshal for Date struct. 实现 UnmarshalJSON 接口

type DateMicro

type DateMicro struct {
	Carbon
}

DateMicro defines a DateMicro struct. 定义 DateMicro 结构体

func NewDateMicro

func NewDateMicro(carbon Carbon) DateMicro

func (DateMicro) GormDataType added in v1.13.1

func (t DateMicro) GormDataType() string

func (DateMicro) MarshalJSON

func (t DateMicro) MarshalJSON() ([]byte, error)

MarshalJSON implements the interface json.Marshal for DateMicro struct. 实现 MarshalJSON 接口

func (DateMicro) String

func (t DateMicro) String() string

String implements the interface Stringer for DateMicro struct. 实现 Stringer 接口

func (*DateMicro) UnmarshalJSON

func (t *DateMicro) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the interface json.Unmarshal for DateMicro struct. 实现 UnmarshalJSON 接口

type DateMilli

type DateMilli struct {
	Carbon
}

DateMilli defines a DateMilli struct. 定义 DateMilli 结构体

func NewDateMilli

func NewDateMilli(carbon Carbon) DateMilli

func (DateMilli) GormDataType added in v1.13.1

func (t DateMilli) GormDataType() string

func (DateMilli) MarshalJSON

func (t DateMilli) MarshalJSON() ([]byte, error)

MarshalJSON implements the interface json.Marshal for DateMilli struct. 实现 MarshalJSON 接口

func (DateMilli) String

func (t DateMilli) String() string

String implements the interface Stringer for DateMilli struct. 实现 Stringer 接口

func (*DateMilli) UnmarshalJSON

func (t *DateMilli) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the interface json.Unmarshal for DateMilli struct. 实现 UnmarshalJSON 接口

type DateNano

type DateNano struct {
	Carbon
}

DateNano defines a DateNano struct. 定义 DateNano 结构体

func NewDateNano

func NewDateNano(carbon Carbon) DateNano

func (DateNano) GormDataType added in v1.13.1

func (t DateNano) GormDataType() string

func (DateNano) MarshalJSON

func (t DateNano) MarshalJSON() ([]byte, error)

MarshalJSON implements the interface json.Marshal for DateNano struct. 实现 MarshalJSON 接口

func (DateNano) String

func (t DateNano) String() string

String implements the interface Stringer for DateNano struct. 实现 Stringer 接口

func (*DateNano) UnmarshalJSON

func (t *DateNano) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the interface json.Unmarshal for DateNano struct. 实现 UnmarshalJSON 接口

type DateTime

type DateTime struct {
	Carbon
}

DateTime defines a DateTime struct. 定义 DateTime 结构体

func NewDateTime

func NewDateTime(carbon Carbon) DateTime

func (DateTime) GormDataType added in v1.13.1

func (t DateTime) GormDataType() string

func (DateTime) MarshalJSON

func (t DateTime) MarshalJSON() ([]byte, error)

MarshalJSON implements the interface json.Marshal for DateTime struct. 实现 MarshalJSON 接口

func (DateTime) String

func (t DateTime) String() string

String implements the interface Stringer for DateTime struct. 实现 Stringer 接口

func (*DateTime) UnmarshalJSON

func (t *DateTime) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the interface json.Unmarshal for DateTime struct. 实现 UnmarshalJSON 接口

type DateTimeMicro

type DateTimeMicro struct {
	Carbon
}

DateTimeMicro defines a DateTimeMicro struct. 定义 DateTimeMicro 结构体

func NewDateTimeMicro

func NewDateTimeMicro(carbon Carbon) DateTimeMicro

func (DateTimeMicro) GormDataType added in v1.13.1

func (t DateTimeMicro) GormDataType() string

func (DateTimeMicro) MarshalJSON

func (t DateTimeMicro) MarshalJSON() ([]byte, error)

MarshalJSON implements the interface json.Marshal for DateTimeMicro struct. 实现 MarshalJSON 接口

func (DateTimeMicro) String

func (t DateTimeMicro) String() string

String implements the interface Stringer for DateTimeMicro struct. 实现 Stringer 接口

func (*DateTimeMicro) UnmarshalJSON

func (t *DateTimeMicro) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the interface json.Unmarshal for DateTimeMicro struct. 实现 UnmarshalJSON 接口

type DateTimeMilli

type DateTimeMilli struct {
	Carbon
}

DateTimeMilli defines a DateTimeMilli struct. 定义 DateTimeMilli 结构体

func NewDateTimeMilli

func NewDateTimeMilli(carbon Carbon) DateTimeMilli

func (DateTimeMilli) GormDataType added in v1.13.1

func (t DateTimeMilli) GormDataType() string

func (DateTimeMilli) MarshalJSON

func (t DateTimeMilli) MarshalJSON() ([]byte, error)

MarshalJSON implements the interface json.Marshal for DateTimeMilli struct. 实现 MarshalJSON 接口

func (DateTimeMilli) String

func (t DateTimeMilli) String() string

String implements the interface Stringer for DateTimeMilli struct. 实现 Stringer 接口

func (*DateTimeMilli) UnmarshalJSON

func (t *DateTimeMilli) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the interface json.Unmarshal for DateTimeMilli struct. 实现 UnmarshalJSON 接口

type DateTimeNano

type DateTimeNano struct {
	Carbon
}

DateTimeNano defines a DateTimeNano struct. 定义 DateTimeNano 结构体

func NewDateTimeNano

func NewDateTimeNano(carbon Carbon) DateTimeNano

func (DateTimeNano) GormDataType added in v1.13.1

func (t DateTimeNano) GormDataType() string

func (DateTimeNano) MarshalJSON

func (t DateTimeNano) MarshalJSON() ([]byte, error)

MarshalJSON implements the interface json.Marshal for DateTimeNano struct. 实现 MarshalJSON 接口

func (DateTimeNano) String

func (t DateTimeNano) String() string

String implements the interface Stringer for DateTimeNano struct. 实现 Stringer 接口

func (*DateTimeNano) UnmarshalJSON

func (t *DateTimeNano) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the interface json.Unmarshal for DateTimeNano struct. 实现 UnmarshalJSON 接口

type Timestamp

type Timestamp struct {
	Carbon
}

Timestamp defines a Timestamp struct. 定义 Timestamp 结构体

func NewTimestamp

func NewTimestamp(carbon Carbon) Timestamp

func (Timestamp) GormDataType added in v1.13.1

func (t Timestamp) GormDataType() string

func (Timestamp) MarshalJSON

func (t Timestamp) MarshalJSON() ([]byte, error)

MarshalJSON implements the interface json.Marshal for Timestamp struct. 实现 MarshalJSON 接口

func (Timestamp) String

func (t Timestamp) String() string

String implements the interface Stringer for Timestamp struct. 实现 Stringer 接口

func (*Timestamp) UnmarshalJSON

func (t *Timestamp) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the interface json.Unmarshal for Timestamp struct. 实现 UnmarshalJSON 接口

type TimestampMicro

type TimestampMicro struct {
	Carbon
}

TimestampMicro defines a TimestampMicro struct. 定义 TimestampMicro 结构体

func NewTimestampMicro

func NewTimestampMicro(carbon Carbon) TimestampMicro

func (TimestampMicro) GormDataType added in v1.13.1

func (t TimestampMicro) GormDataType() string

func (TimestampMicro) MarshalJSON

func (t TimestampMicro) MarshalJSON() ([]byte, error)

MarshalJSON implements the interface MarshalJSON for TimestampMicro struct. 实现 MarshalJSON 接口

func (TimestampMicro) String

func (t TimestampMicro) String() string

String implements the interface Stringer for TimestampMicro struct. 实现 Stringer 接口

func (*TimestampMicro) UnmarshalJSON

func (t *TimestampMicro) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the interface json.Unmarshal for TimestampMicro struct. 实现 UnmarshalJSON 接口

type TimestampMilli

type TimestampMilli struct {
	Carbon
}

TimestampMilli defines a TimestampMilli struct. 定义 TimestampMilli 结构体

func NewTimestampMilli

func NewTimestampMilli(carbon Carbon) TimestampMilli

func (TimestampMilli) GormDataType added in v1.13.1

func (t TimestampMilli) GormDataType() string

func (TimestampMilli) MarshalJSON

func (t TimestampMilli) MarshalJSON() ([]byte, error)

MarshalJSON implements the interface json.Marshal for TimestampMilli struct. 实现 MarshalJSON 接口

func (TimestampMilli) String

func (t TimestampMilli) String() string

String implements the interface Stringer for TimestampMilli struct. 实现 Stringer 接口

func (*TimestampMilli) UnmarshalJSON

func (t *TimestampMilli) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the interface json.Unmarshal for TimestampMilli struct. 实现 UnmarshalJSON 接口

type TimestampNano

type TimestampNano struct {
	Carbon
}

TimestampNano defines a TimestampNano struct. 定义 TimestampNano 结构体

func NewTimestampNano

func NewTimestampNano(carbon Carbon) TimestampNano

func (TimestampNano) GormDataType added in v1.13.1

func (t TimestampNano) GormDataType() string

func (TimestampNano) MarshalJSON

func (t TimestampNano) MarshalJSON() ([]byte, error)

MarshalJSON implements the interface json.Marshal for TimestampNano struct. 实现 MarshalJSON 接口

func (TimestampNano) String

func (t TimestampNano) String() string

String implements the interface Stringer for TimestampNano struct. 实现 Stringer 接口

func (*TimestampNano) UnmarshalJSON

func (t *TimestampNano) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the interface json.Unmarshal for TimestampNano struct. 实现 UnmarshalJSON 接口

Jump to

Keyboard shortcuts

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