carbon

package module
v1.6.5 Latest Latest
Warning

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

Go to latest
Published: May 1, 2022 License: MIT Imports: 9 Imported by: 4

README

Carbon

Carbon Release Go Test Go Report Card Go Coverage Carbon Doc License

English | 简体中文 | 日本語

Introduction

A simple, semantic and developer-friendly golang package for datetime

Carbon has been included by awesome-go, if you think it is helpful, please give me a star

github.com/golang-module/carbon

gitee.com/go-package/carbon

Installation
Go version < 1.16
// By github
go get -u github.com/golang-module/carbon

import (
    "github.com/golang-module/carbon"
)

// By gitee
go get -u gitee.com/go-package/carbon

import (
    "gitee.com/go-package/carbon"
)               
Go version >= 1.16
// By github
go get -u github.com/golang-module/carbon/v2

import (
    "github.com/golang-module/carbon/v2"
)

// By gitee
go get -u gitee.com/go-package/carbon/v2

import (
    "gitee.com/go-package/carbon/v2"
)               
Usage and example

The default timezone is Local, assuming the current time is 2020-08-05 13:14:15

Yesterday, today and tomorrow
// Return datetime of today
fmt.Sprintf("%s", carbon.Now()) // 2020-08-05 13:14:15
carbon.Now().ToDateTimeString() // 2020-08-05 13:14:15
// Return date of today
carbon.Now().ToDateString() // 2020-08-05
// Return time of today
carbon.Now().ToTimeString() // 13:14:15
// Return datetime of today in a given timezone
carbon.Now(Carbon.NewYork).ToDateTimeString() // 2020-08-05 14:14:15
// Return timestamp with second of today
carbon.Now().Timestamp() // 1596604455
// Return timestamp with millisecond of today
carbon.Now().TimestampMilli() // 1596604455000
// Return timestamp with microsecond of today
carbon.Now().TimestampMicro() // 1596604455000000
// Return timestamp with nanosecond of today
carbon.Now().TimestampNano() // 1596604455000000000

// Return datetime of yesterday 
fmt.Sprintf("%s", carbon.Yesterday()) // 2020-08-04 13:14:15
carbon.Yesterday().ToDateTimeString() // 2020-08-04 13:14:15
// Return date of yesterday
carbon.Yesterday().ToDateString() // 2020-08-04
// Return time of yesterday
carbon.Yesterday().ToTimeString() // 13:14:15
// Return datetime of yesterday on a given day
carbon.Parse("2021-01-28 13:14:15").Yesterday().ToDateTimeString() // 2021-01-27 13:14:15
// Return datetime of yesterday in a given timezone
carbon.Yesterday(Carbon.NewYork).ToDateTimeString() // 2020-08-04 14:14:15
// Return timestamp with second of yesterday
carbon.Yesterday().Timestamp() // 1596518055
// Return timestamp with millisecond of yesterday
carbon.Yesterday().TimestampMilli() // 1596518055000
// Return timestamp with microsecond of yesterday
carbon.Yesterday().TimestampMicro() // 1596518055000000
// Return timestamp with nanosecond of yesterday
carbon.Yesterday().TimestampNano() // 1596518055000000000

// Return datetime of tomorrow
fmt.Sprintf("%s", carbon.Tomorrow()) // 2020-08-06 13:14:15
carbon.Tomorrow().ToDateTimeString() // 2020-08-06 13:14:15
// Return date of tomorrow
carbon.Tomorrow().ToDateString() // 2020-08-06
// Return time of tomorrow
carbon.Tomorrow().ToTimeString() // 13:14:15
// Return datetime of tomorrow on a given day
carbon.Parse("2021-01-28 13:14:15").Tomorrow().ToDateTimeString() // 2021-01-29 13:14:15
// Return datetime of tomorrow in a given timezone
carbon.Tomorrow(Carbon.NewYork).ToDateTimeString() // 2020-08-06 14:14:15
// Return timestamp with second of tomorrow
carbon.Tomorrow().Timestamp() // 1596690855
// Return timestamp with millisecond of tomorrow
carbon.Tomorrow().TimestampMilli() // 1596690855000
// Return timestamp with microsecond of tomorrow
carbon.Tomorrow().TimestampMicro() // 1596690855000000
// Return timestamp with nanosecond of tomorrow
carbon.Tomorrow().TimestampNano() // 1596690855000000000
Create a Carbon instance
// Create a Carbon instance from a given timestamp with second
carbon.CreateFromTimestamp(-1).ToString() // 1970-01-01 07:59:59 +0800 CST
carbon.CreateFromTimestamp(0).ToString() // 1970-01-01 08:00:00 +0800 CST
carbon.CreateFromTimestamp(1).ToString() // 1970-01-01 08:00:01 +0800 CST
carbon.CreateFromTimestamp(1649735755).ToString() // 2022-04-12 11:55:55 +0800 CST
// Create a Carbon instance from a given timestamp with millisecond
carbon.CreateFromTimestampMilli(1649735755981).ToString() // 2022-04-12 11:55:55.981 +0800 CST
// Create a Carbon instance from a given timestamp with microsecond
carbon.CreateFromTimestampMicro(1649735755981566).ToString() // 2022-04-12 11:55:55.981566 +0800 CST
// Create a Carbon instance from a given timestamp with nanosecond
carbon.CreateFromTimestampNano(1649735755981566000).ToString() // 2022-04-12 11:55:55.981566 +0800 CST

// Create a Carbon instance from a given date and time.
carbon.CreateFromDateTime(2020, 8, 5, 13, 14, 15).ToDateTimeString() // 2020-08-05 13:14:15
// Create a Carbon instance from a given date and time with millisecond. 
carbon.CreateFromDateTimeMilli(2020, 1, 1, 13, 14, 15, 999).ToString() // 2020-01-01 13:14:15.999 +0800 CST
// Create a Carbon instance from a given date and time with microsecond. 
carbon.CreateFromDateTimeMicro(2020, 1, 1, 13, 14, 15, 999999).ToString() // 2020-01-01 13:14:15.999999 +0800 CST
// Create a Carbon instance from a given date and time with nanosecond. 
carbon.CreateFromDateTimeNano(2020, 1, 1, 13, 14, 15, 999999999).ToString() // 2020-01-01 13:14:15.999999999 +0800 CST

// Create a Carbon instance from a given year, month and day
carbon.CreateFromDate(2020, 8, 5).ToDateTimeString() // 2020-08-05 13:14:15
// Create a Carbon instance from a given hour, minute and second
carbon.CreateFromTime(13, 14, 15).ToDateTimeString() // 2020-08-05 13:14:15
Parse a standard string as a Carbon instance
carbon.Parse("").ToDateTimeString() // empty string
carbon.Parse("0").ToDateTimeString() // empty string
carbon.Parse("0000-00-00 00:00:00").ToDateTimeString() // empty string
carbon.Parse("0000-00-00").ToDateTimeString() // empty string
carbon.Parse("00:00:00").ToDateTimeString() // empty string

carbon.Parse("2020-08-05").ToString() // 2020-08-05 00:00:00 +0800 CST
carbon.Parse("2020-08-05 13:14:15").ToString() // 2020-08-05 13:14:15 +0800 CST
carbon.Parse("2020-08-05 13:14:15.999").ToString() // 2020-08-05 13:14:15.999 +0800 CST
carbon.Parse("2020-08-05 13:14:15.999999").ToString() // 2020-08-05 13:14:15.999999 +0800 CST
carbon.Parse("2020-08-05 13:14:15.999999999").ToString() // 2020-08-05 13:14:15.999999999 +0800 CST

carbon.Parse("2020-08-05T13:14:15+08:00").ToString() // 2020-08-05 13:14:15 +0800 CST
carbon.Parse("2020-08-05T13:14:15.999+08:00").ToString() // 2020-08-05 13:14:15.999 +0800 CST
carbon.Parse("2020-08-05T13:14:15.999999+08:00").ToString() // 2020-08-05 13:14:15.999999 +0800 CST
carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToString() // 2020-08-05 13:14:15.999999999 +0800 CST

carbon.Parse("20200805").ToString() // 2020-08-05 00:00:00 +0800 CST
carbon.Parse("20200805131415").ToString() // 2020-08-05 13:14:15 +0800 CST
carbon.Parse("20200805131415.999").ToString() // 2020-08-05 13:14:15.999 +0800 CST
carbon.Parse("20200805131415.999999").ToString() // 2020-08-05 13:14:15.999999 +0800 CST
carbon.Parse("20200805131415.999999999").ToString() // 2020-08-05 13:14:15.999999999 +0800 CST
Parse a string as a Carbon instance by format
carbon.ParseByFormat("2020|08|05 13|14|15", "Y|m|d H|i|s").ToDateTimeString() // 2020-08-05 13:14:15
carbon.ParseByFormat("It is 2020-08-05 13:14:15", "\\I\\t \\i\\s Y-m-d H:i:s").ToDateTimeString() // 2020-08-05 13:14:15
carbon.ParseByFormat("今天是 2020年08月05日13时14分15秒", "今天是 Y年m月d日H时i分s秒").ToDateTimeString() // 2020-08-05 13:14:15
Parse a string as a Carbon instance by layout
carbon.ParseByLayout("2020|08|05 13|14|15", "2006|01|02 15|04|05").ToDateTimeString() // 2020-08-05 13:14:15
carbon.ParseByLayout("It is 2020-08-05 13:14:15", "It is 2006-01-02 15:04:05").ToDateTimeString() // 2020-08-05 13:14:15
carbon.ParseByLayout("今天是 2020年08月05日13时14分15秒", "今天是 2006年01月02日15时04分05秒").ToDateTimeString() // 2020-08-05 13:14:15
Convert between Carbon and Time
// Convert Time.time into Carbon
carbon.Time2Carbon(time.Now())
// Convert Carbon into Time.time
carbon.Now().Carbon2Time()
Start and end
// Start of the century
carbon.Parse("2020-08-05 13:14:15").StartOfCentury().ToDateTimeString() // 2000-01-01 00:00:00
// End of the century
carbon.Parse("2020-08-05 13:14:15").EndOfCentury().ToDateTimeString() // 2999-12-31 23:59:59

// Start of the decade
carbon.Parse("2020-08-05 13:14:15").StartOfDecade().ToDateTimeString() // 2020-01-01 00:00:00
carbon.Parse("2021-08-05 13:14:15").StartOfDecade().ToDateTimeString() // 2020-01-01 00:00:00
carbon.Parse("2029-08-05 13:14:15").StartOfDecade().ToDateTimeString() // 2020-01-01 00:00:00
// End of the decade
carbon.Parse("2020-08-05 13:14:15").EndOfDecade().ToDateTimeString() // 2029-12-31 23:59:59
carbon.Parse("2021-08-05 13:14:15").EndOfDecade().ToDateTimeString() // 2029-12-31 23:59:59
carbon.Parse("2029-08-05 13:14:15").EndOfDecade().ToDateTimeString() // 2029-12-31 23:59:59

// Start of the year
carbon.Parse("2020-08-05 13:14:15").StartOfYear().ToDateTimeString() // 2020-01-01 00:00:00
// End of the year
carbon.Parse("2020-08-05 13:14:15").EndOfYear().ToDateTimeString() // 2020-12-31 23:59:59

// Start of the quarter
carbon.Parse("2020-08-05 13:14:15").StartOfQuarter().ToDateTimeString() // 2020-07-01 00:00:00
// End of the quarter
carbon.Parse("2020-08-05 13:14:15").EndOfQuarter().ToDateTimeString() // 2020-09-30 23:59:59

// Start of the month
carbon.Parse("2020-08-05 13:14:15").StartOfMonth().ToStartTimeString() // 2020-08-01 00:00:00
// End of the month
carbon.Parse("2020-08-05 13:14:15").EndOfMonth().ToDateTimeString() // 2020-08-31 23:59:59

// Start of the week
carbon.Parse("2020-08-05 13:14:15").StartOfWeek().ToDateTimeString() // 2020-08-02 00:00:00
carbon.Parse("2020-08-05 13:14:15").SetWeekStartsAt(carbon.Sunday).StartOfWeek().ToDateTimeString() // 2020-08-02 00:00:00
carbon.Parse("2020-08-05 13:14:15").SetWeekStartsAt(carbon.Monday).StartOfWeek().ToDateTimeString() // 2020-08-03 00:00:00
// End of the week
carbon.Parse("2020-08-05 13:14:15").EndOfWeek().ToDateTimeString() // 2020-08-08 23:59:59
carbon.Parse("2020-08-05 13:14:15").SetWeekStartsAt(carbon.Sunday).EndOfWeek().ToDateTimeString() // 2020-08-08 23:59:59
carbon.Parse("2020-08-05 13:14:15").SetWeekStartsAt(carbon.Monday).EndOfWeek().ToDateTimeString() // 2020-08-09 23:59:59

// Start of the day
carbon.Parse("2020-08-05 13:14:15").StartOfDay().ToDateTimeString() // 2020-08-05 00:00:00
// End of the day
carbon.Parse("2020-08-05 13:14:15").EndOfDay().ToDateTimeString() // 2020-08-05 23:59:59

// Start of the hour
carbon.Parse("2020-08-05 13:14:15").StartOfHour().ToDateTimeString() // 2020-08-05 13:00:00
// End of the hour
carbon.Parse("2020-08-05 13:14:15").EndOfHour().ToDateTimeString() // 2020-08-05 13:59:59

// Start of the minute
carbon.Parse("2020-08-05 13:14:15").StartOfMinute().ToDateTimeString() // 2020-08-05 13:14:00
// End of the minute
carbon.Parse("2020-08-05 13:14:15").EndOfMinute().ToDateTimeString() // 2020-08-05 13:14:59

// Start of the second
carbon.Parse("2020-08-05 13:14:15").StartOfSecond().ToString() // 2020-08-05 13:14:15 +0800 CST
// End of the second
carbon.Parse("2020-08-05 13:14:15").EndOfSecond().ToString() // 2020-08-05 13:14:15.999999999 +0800 CST
Addition and subtraction
// Add three centuries
carbon.Parse("2020-02-29 13:14:15").AddCenturies(3).ToDateTimeString() // 2320-02-29 13:14:15
// Add three centuries without overflowing month
carbon.Parse("2020-02-29 13:14:15").AddCenturiesNoOverflow(3).ToDateTimeString() // 2320-02-29 13:14:15
// Add one century
carbon.Parse("2020-02-29 13:14:15").AddCentury().ToDateTimeString() // 2120-02-29 13:14:15
// Add one century without overflowing month
carbon.Parse("2020-02-29 13:14:15").AddCenturyNoOverflow().ToDateTimeString() // 2120-02-29 13:14:15
// Subtract three centuries
carbon.Parse("2020-02-29 13:14:15").SubCenturies(3).ToDateTimeString() // 1720-02-29 13:14:15
// Subtract three centuries without overflowing month
carbon.Parse("2020-02-29 13:14:15").SubCenturiesNoOverflow(3).ToDateTimeString() // 1720-02-29 13:14:15
// Subtract one century
carbon.Parse("2020-02-29 13:14:15").SubCentury().ToDateTimeString() // 1920-02-29 13:14:15
// Subtract one century without overflowing month
carbon.Parse("2020-02-29 13:14:15").SubCenturyNoOverflow().ToDateTimeString() // 1920-02-20 13:14:15

// Add three decades
carbon.Parse("2020-02-29 13:14:15").AddDecades(3).ToDateTimeString() // 2050-03-01 13:14:15
// Add three decades without overflowing month
carbon.Parse("2020-02-29 13:14:15").AddDecadesNoOverflow(3).ToDateTimeString() // 2050-02-28 13:14:15
// Add one decade
carbon.Parse("2020-02-29 13:14:15").AddDecade().ToDateTimeString() // 2030-03-01 13:14:15
// Add one decade without overflowing month
carbon.Parse("2020-02-29 13:14:15").AddDecadeNoOverflow().ToDateTimeString() // 2030-02-28 13:14:15
// Subtract three decades
carbon.Parse("2020-02-29 13:14:15").SubDecades(3).ToDateTimeString() // 1990-03-01 13:14:15
// Subtract three decades without overflowing month
carbon.Parse("2020-02-29 13:14:15").SubDecadesNoOverflow(3).ToDateTimeString() // 1990-02-28 13:14:15
// Subtract one decade
carbon.Parse("2020-02-29 13:14:15").SubDecade().ToDateTimeString() // 2010-03-01 13:14:15
// Subtract one decade without overflowing month
carbon.Parse("2020-02-29 13:14:15").SubDecadeNoOverflow().ToDateTimeString() // 2010-02-28 13:14:15

// Add three years
carbon.Parse("2020-02-29 13:14:15").AddYears(3).ToDateTimeString() // 2023-03-01 13:14:15
// Add three years without overflowing month
carbon.Parse("2020-02-29 13:14:15").AddYearsNoOverflow(3).ToDateTimeString() // 2023-02-28 13:14:15
// Add one year
carbon.Parse("2020-02-29 13:14:15").AddYear().ToDateTimeString() // 2021-03-01 13:14:15
// Add one year without overflowing month
carbon.Parse("2020-02-29 13:14:15").AddYearNoOverflow().ToDateTimeString() // 2021-02-28 13:14:15
// Subtract three years
carbon.Parse("2020-02-29 13:14:15").SubYears(3).ToDateTimeString() // 2017-03-01 13:14:15
// Subtract three years without overflowing month
carbon.Parse("2020-02-29 13:14:15").SubYearsNoOverflow(3).ToDateTimeString() // 2017-02-28 13:14:15
// Subtract one year
carbon.Parse("2020-02-29 13:14:15").SubYear().ToDateTimeString() // 2019-03-01 13:14:15
// Subtract one year without overflowing month
carbon.Parse("2020-02-29 13:14:15").SubYearNoOverflow().ToDateTimeString() // 2019-02-28 13:14:15

// Add three quarters
carbon.Parse("2019-08-31 13:14:15").AddQuarters(3).ToDateTimeString() // 2019-03-02 13:14:15
// Add three quarters without overflowing month
carbon.Parse("2019-08-31 13:14:15").AddQuartersNoOverflow(3).ToDateTimeString() // 2019-02-29 13:14:15
// Add one quarter
carbon.Parse("2019-11-30 13:14:15").AddQuarter().ToDateTimeString() // 2020-03-01 13:14:15
// Add one quarter without overflowing month
carbon.Parse("2019-11-30 13:14:15").AddQuarterNoOverflow().ToDateTimeString() // 2020-02-29 13:14:15
// Subtract three quarters
carbon.Parse("2019-08-31 13:14:15").SubQuarters(3).ToDateTimeString() // 2019-03-03 13:14:15
// Subtract three quarters without overflowing month
carbon.Parse("2019-08-31 13:14:15").SubQuartersNoOverflow(3).ToDateTimeString() // 2019-02-28 13:14:15
// Subtract one quarter
carbon.Parse("2020-05-31 13:14:15").SubQuarter().ToDateTimeString() // 2020-03-02 13:14:15
// Subtract one quarter without overflowing month
carbon.Parse("2020-05-31 13:14:15").SubQuarterNoOverflow().ToDateTimeString() // 2020-02-29 13:14:15

// Add three months
carbon.Parse("2020-02-29 13:14:15").AddMonths(3).ToDateTimeString() // 2020-05-29 13:14:15
// Add three months without overflowing month
carbon.Parse("2020-02-29 13:14:15").AddMonthsNoOverflow(3).ToDateTimeString() // 2020-05-29 13:14:15
// Add one month
carbon.Parse("2020-01-31 13:14:15").AddMonth().ToDateTimeString() // 2020-03-02 13:14:15
// Add one month without overflowing month
carbon.Parse("2020-01-31 13:14:15").AddMonthNoOverflow().ToDateTimeString() // 2020-02-29 13:14:15
// Subtract three months
carbon.Parse("2020-02-29 13:14:15").SubMonths(3).ToDateTimeString() // 2019-11-29 13:14:15
// Subtract three months without overflowing month
carbon.Parse("2020-02-29 13:14:15").SubMonthsNoOverflow(3).ToDateTimeString() // 2019-11-29 13:14:15
// Subtract one month
carbon.Parse("2020-03-31 13:14:15").SubMonth().ToDateTimeString() // 2020-03-02 13:14:15
// Subtract one month without overflowing month
carbon.Parse("2020-03-31 13:14:15").SubMonthNoOverflow().ToDateTimeString() // 2020-02-29 13:14:15

// Add three weeks
carbon.Parse("2020-02-29 13:14:15").AddWeeks(3).ToDateTimeString() // 2020-03-21 13:14:15
// Add one week
carbon.Parse("2020-02-29 13:14:15").AddWeek().ToDateTimeString() // 2020-03-07 13:14:15
// Subtract three weeks
carbon.Parse("2020-02-29 13:14:15").SubWeeks(3).ToDateTimeString() // 2020-02-08 13:14:15
// Subtract three week
carbon.Parse("2020-02-29 13:14:15").SubWeek().ToDateTimeString() // 2020-02-22 13:14:15

// Add three days
carbon.Parse("2020-08-05 13:14:15").AddDays(3).ToDateTimeString() // 2020-08-08 13:14:15
// Add one day
carbon.Parse("2020-08-05 13:14:15").AddDay().ToDateTimeString() // 2020-08-05 13:14:15
// Subtract three days
carbon.Parse("2020-08-05 13:14:15").SubDays(3).ToDateTimeString() // 2020-08-02 13:14:15
// Subtract one day
carbon.Parse("2020-08-05 13:14:15").SubDay().ToDateTimeString() // 2020-08-04 13:14:15

// Add three hours
carbon.Parse("2020-08-05 13:14:15").AddHours(3).ToDateTimeString() // 2020-08-05 16:14:15
// Add two and a half hours
carbon.Parse("2020-08-05 13:14:15").AddDuration("2.5h").ToDateTimeString() // 2020-08-05 15:44:15
carbon.Parse("2020-08-05 13:14:15").AddDuration("2h30m").ToDateTimeString() // 2020-08-05 15:44:15
// Add one hour
carbon.Parse("2020-08-05 13:14:15").AddHour().ToDateTimeString() // 2020-08-05 14:14:15
// Subtract three hours
carbon.Parse("2020-08-05 13:14:15").SubHours(3).ToDateTimeString() // 2020-08-05 10:14:15
// Subtract two and a half hours
carbon.Parse("2020-08-05 13:14:15").SubDuration("2.5h").ToDateTimeString() // 2020-08-05 10:44:15
carbon.Parse("2020-08-05 13:14:15").SubDuration("2h30m").ToDateTimeString() // 2020-08-05 10:44:15
// Subtract one hour
carbon.Parse("2020-08-05 13:14:15").SubHour().ToDateTimeString() // 2020-08-05 12:14:15

// Add three minutes
carbon.Parse("2020-08-05 13:14:15").AddMinutes(3).ToDateTimeString() // 2020-08-05 13:17:15
// Add two and a half minutes
carbon.Parse("2020-08-05 13:14:15").AddDuration("2.5m").ToDateTimeString() // 2020-08-05 13:16:45
carbon.Parse("2020-08-05 13:14:15").AddDuration("2m30s").ToDateTimeString() // 2020-08-05 13:16:45
// Add one minute
carbon.Parse("2020-08-05 13:14:15").AddMinute().ToDateTimeString() // 2020-08-05 13:15:15
// Subtract three minutes
carbon.Parse("2020-08-05 13:14:15").SubMinutes(3).ToDateTimeString() // 2020-08-05 13:11:15
// Subtract two and a half minutes
carbon.Parse("2020-08-05 13:14:15").SubDuration("2.5m").ToDateTimeString() // 2020-08-05 13:11:45
// Subtract one minute
carbon.Parse("2020-08-05 13:14:15").SubMinute().ToDateTimeString() // 2020-08-05 13:13:15

// Add three seconds
carbon.Parse("2020-08-05 13:14:15").AddSeconds(3).ToDateTimeString() // 2020-08-05 13:14:18
// Add two and a half seconds
carbon.Parse("2020-08-05 13:14:15").AddDuration("2.5s").ToDateTimeString() // 2020-08-05 13:14:17
// Add one second
carbon.Parse("2020-08-05 13:14:15").AddSecond().ToDateTimeString() // 2020-08-05 13:14:16
// Subtract three seconds
carbon.Parse("2020-08-05 13:14:15").SubSeconds(3).ToDateTimeString() // 2020-08-05 13:14:12
// Subtract two and a half seconds
carbon.Parse("2020-08-05 13:14:15").SubDuration("2.5s").ToDateTimeString() // 2020-08-05 13:14:12
// Subtract one second
carbon.Parse("2020-08-05 13:14:15").SubSecond().ToDateTimeString() // 2020-08-05 13:14:14

// Add three milliseconds
carbon.Parse("2020-08-05 13:14:15.222222222").AddMilliseconds(3).ToString() // 2020-08-05 13:14:15.225222222 +0800 CST
// Add one millisecond
carbon.Parse("2020-08-05 13:14:15.222222222").AddMillisecond().ToString() // 2020-08-05 13:14:15.223222222 +0800 CST
// Subtract three milliseconds
carbon.Parse("2020-08-05 13:14:15.222222222").SubMilliseconds(3).ToString() // 2020-08-05 13:14:15.219222222 +0800 CST
// Subtract one millisecond
carbon.Parse("2020-08-05 13:14:15.222222222").SubMillisecond().ToString() // 2020-08-05 13:14:15.221222222 +0800 CST

// Add three microseconds
carbon.Parse("2020-08-05 13:14:15.222222222").AddMicroseconds(3).ToString() // 2020-08-05 13:14:15.222225222 +0800 CST
// Add one microsecond
carbon.Parse("2020-08-05 13:14:15.222222222").AddMicrosecond().ToString() // 2020-08-05 13:14:15.222223222 +0800 CST
// Subtract three microseconds
carbon.Parse("2020-08-05 13:14:15.222222222").SubMicroseconds(3).ToString() // 2020-08-05 13:14:15.222219222 +0800 CST
// Subtract one microsecond
carbon.Parse("2020-08-05 13:14:15.222222222").SubMicrosecond().ToString() // 2020-08-05 13:14:15.222221222 +0800 CST

// Add three nanoseconds
carbon.Parse("2020-08-05 13:14:15.222222222").AddNanoseconds(3).ToString() // 2020-08-05 13:14:15.222222225 +0800 CST
// Add one nanosecond
carbon.Parse("2020-08-05 13:14:15.222222222").AddNanossecond().ToString() // 2020-08-05 13:14:15.222222223 +0800 CST
// Subtract three nanoseconds
carbon.Parse("2020-08-05 13:14:15.222222222").SubNanosseconds(3).ToString() // 2020-08-05 13:14:15.222222219 +0800 CST
// Subtract one nanosecond
carbon.Parse("2020-08-05 13:14:15.222222222").SubNanossecond().ToString() // 2020-08-05 13:14:15.222222221 +0800 CST
Difference
// Difference in years
carbon.Parse("2021-08-05 13:14:15").DiffInYears(carbon.Parse("2020-08-05 13:14:15")) // -1
// Difference in years with absolute value
carbon.Parse("2021-08-05 13:14:15").DiffAbsInYears(carbon.Parse("2020-08-05 13:14:15")) // 1

// Difference in months
carbon.Parse("2020-08-05 13:14:15").DiffInMonths(carbon.Parse("2020-07-05 13:14:15")) // -1
// Difference in months with absolute value
carbon.Parse("2020-08-05 13:14:15").DiffAbsInMonths(carbon.Parse("2020-07-05 13:14:15")) // 1

// Difference in weeks
carbon.Parse("2020-08-05 13:14:15").DiffInWeeks(carbon.Parse("2020-07-28 13:14:15")) // -1
// Difference in weeks with absolute value
carbon.Parse("2020-08-05 13:14:15").DiffAbsInWeeks(carbon.Parse("2020-07-28 13:14:15")) // 1

// Difference in days
carbon.Parse("2020-08-05 13:14:15").DiffInDays(carbon.Parse("2020-08-04 13:14:15")) // -1
// Difference in days with absolute value
carbon.Parse("2020-08-05 13:14:15").DiffAbsInDays(carbon.Parse("2020-08-04 13:14:15")) // 1

// Difference in hours
carbon.Parse("2020-08-05 13:14:15").DiffInHours(carbon.Parse("2020-08-05 12:14:15")) // -1
// Difference in hours with absolute value
carbon.Parse("2020-08-05 13:14:15").DiffAbsInHours(carbon.Parse("2020-08-05 12:14:15")) // 1

// Difference in minutes
carbon.Parse("2020-08-05 13:14:15").DiffInMinutes(carbon.Parse("2020-08-05 13:13:15")) // -1
// Difference in minutes with absolute value
carbon.Parse("2020-08-05 13:14:15").DiffAbsInMinutes(carbon.Parse("2020-08-05 13:13:15")) // 1

// Difference in seconds
carbon.Parse("2020-08-05 13:14:15").DiffInSeconds(carbon.Parse("2020-08-05 13:14:14")) // -1
// Difference in seconds with absolute value
carbon.Parse("2020-08-05 13:14:15").DiffAbsInSeconds(carbon.Parse("2020-08-05 13:14:14")) // 1

// Difference in string
carbon.Now().DiffInString() // just now
carbon.Now().AddYearsNoOverflow(1).DiffInString() // -1 year
carbon.Now().SubYearsNoOverflow(1).DiffInString() // 1 year
// Difference in string with absolute value
carbon.Now().DiffAbsInString(carbon.Now()) // just now
carbon.Now().AddYearsNoOverflow(1).DiffAbsInString(carbon.Now()) // 1 year
carbon.Now().SubYearsNoOverflow(1).DiffAbsInString(carbon.Now()) // 1 year

// Difference in a human-readable format
carbon.Parse("2020-08-05 13:14:15").DiffForHumans() // just now
carbon.Parse("2019-08-05 13:14:15").DiffForHumans() // 1 year ago
carbon.Parse("2018-08-05 13:14:15").DiffForHumans() // 2 years ago
carbon.Parse("2021-08-05 13:14:15").DiffForHumans() // 1 year from now
carbon.Parse("2022-08-05 13:14:15").DiffForHumans() // 2 years from now
// Difference in a human-readable format from now time
carbon.Parse("2020-08-05 13:14:15").DiffForHumans(carbon.Now()) // 1 year before
carbon.Parse("2019-08-05 13:14:15").DiffForHumans(carbon.Now()) // 2 years before
carbon.Parse("2018-08-05 13:14:15").DiffForHumans(carbon.Now()) // 1 year after
carbon.Parse("2022-08-05 13:14:15").DiffForHumans(carbon.Now()) // 2 years after
Comparison
// Whether is zero time
carbon.Parse("").IsZero() // true
carbon.Parse("0").IsZero() // true
carbon.Parse("0000-00-00 00:00:00").IsZero() // true
carbon.Parse("0000-00-00").IsZero() // true
carbon.Parse("00:00:00").IsZero() // true
carbon.Parse("2020-08-05 00:00:00").IsZero() // false
carbon.Parse("2020-08-05").IsZero() // false
carbon.Parse("2020-08-05").SetTimezone("xxx").IsZero() // false

// Whether is valid time
carbon.Parse("").IsValid() // false
carbon.Parse("0").IsValid() // false
carbon.Parse("0000-00-00 00:00:00").IsValid() // false
carbon.Parse("0000-00-00").IsValid() // false
carbon.Parse("00:00:00").IsValid() // false
carbon.Parse("2020-08-05 00:00:00").IsValid() // true
carbon.Parse("2020-08-05").IsValid() // true
carbon.Parse("2020-08-05").SetTimezone("xxx").IsValid() // false

// Whether is invalid time
carbon.Parse("").IsInvalid() // true
carbon.Parse("0").IsInvalid() // true
carbon.Parse("0000-00-00 00:00:00").IsInvalid() // true
carbon.Parse("0000-00-00").IsInvalid() // true
carbon.Parse("00:00:00").IsInvalid() // true
carbon.Parse("2020-08-05 00:00:00").IsInvalid() // false
carbon.Parse("2020-08-05").IsInvalid() // false
carbon.Parse("2020-08-05").SetTimezone("xxx").IsInvalid() // true

// Whether is now time
carbon.Now().IsNow() // true
// Whether is future time
carbon.Tomorrow().IsFuture() // true
// Whether is pass time
carbon.Yesterday().IsPast() // true

// Whether is a leap year
carbon.Parse("2020-08-05 13:14:15").IsLeapYear() // true
// Whether is a long year
carbon.Parse("2020-08-05 13:14:15").IsLongYear() // true

// Whether is January 
carbon.Parse("2020-08-05 13:14:15").IsJanuary() // false
// Whether is February
carbon.Parse("2020-08-05 13:14:15").IsFebruary() // false
// Whether is March
carbon.Parse("2020-08-05 13:14:15").IsMarch() // false
// Whether is April
carbon.Parse("2020-08-05 13:14:15").IsApril()  // false
// Whether is May
carbon.Parse("2020-08-05 13:14:15").IsMay() // false
// Whether is June
carbon.Parse("2020-08-05 13:14:15").IsJune() // false
// Whether is July
carbon.Parse("2020-08-05 13:14:15").IsJuly() // false
// Whether is August
carbon.Parse("2020-08-05 13:14:15").IsAugust() // false
// Whether is September
carbon.Parse("2020-08-05 13:14:15").IsSeptember() // true
// Whether is October
carbon.Parse("2020-08-05 13:14:15").IsOctober() // false
// Whether is November
carbon.Parse("2020-08-05 13:14:15").IsNovember() // false
// Whether is December
carbon.Parse("2020-08-05 13:14:15").IsDecember() // false

// Whether is Monday
carbon.Parse("2020-08-05 13:14:15").IsMonday() // false
// Whether is Tuesday
carbon.Parse("2020-08-05 13:14:15").IsTuesday() // true
// Whether is Wednesday
carbon.Parse("2020-08-05 13:14:15").IsWednesday() // false
// Whether is Thursday
carbon.Parse("2020-08-05 13:14:15").IsThursday() // false
// Whether is Friday
carbon.Parse("2020-08-05 13:14:15").IsFriday() // false
// Whether is Saturday
carbon.Parse("2020-08-05 13:14:15").IsSaturday() // false
// Whether is Sunday
carbon.Parse("2020-08-05 13:14:15").IsSunday() // false
// Whether is weekday
carbon.Parse("2020-08-05 13:14:15").IsWeekday() // false
// Whether is weekend
carbon.Parse("2020-08-05 13:14:15").IsWeekend() // true

// Whether is yesterday
carbon.Parse("2020-08-04 13:14:15").IsYesterday() // true
carbon.Parse("2020-08-04 00:00:00").IsYesterday() // true
carbon.Parse("2020-08-04").IsYesterday() // true
// Whether is today
carbon.Parse("2020-08-05 13:14:15").IsToday() // true
carbon.Parse("2020-08-05 00:00:00").IsToday() // true
carbon.Parse("2020-08-05").IsToday() // true
// Whether is tomorrow
carbon.Parse("2020-08-06 13:14:15").IsTomorrow() // true
carbon.Parse("2020-08-06 00:00:00").IsTomorrow() // true
carbon.Parse("2020-08-06").IsTomorrow() // true

// Whether greater than
carbon.Parse("2020-08-05 13:14:15").Gt(carbon.Parse("2020-08-04 13:14:15")) // true
carbon.Parse("2020-08-05 13:14:15").Gt(carbon.Parse("2020-08-05 13:14:15")) // false
carbon.Parse("2020-08-05 13:14:15").Compare(">", carbon.Parse("2020-08-04 13:14:15")) // true
carbon.Parse("2020-08-05 13:14:15").Compare(">", carbon.Parse("2020-08-05 13:14:15")) // false

// Whether less than
carbon.Parse("2020-08-05 13:14:15").Lt(carbon.Parse("2020-08-06 13:14:15")) // true
carbon.Parse("2020-08-05 13:14:15").Lt(carbon.Parse("2020-08-05 13:14:15")) // false
carbon.Parse("2020-08-05 13:14:15").Compare("<", carbon.Parse("2020-08-06 13:14:15")) // true
carbon.Parse("2020-08-05 13:14:15").Compare("<", carbon.Parse("2020-08-05 13:14:15")) // false

// Whether equal
carbon.Parse("2020-08-05 13:14:15").Eq(carbon.Parse("2020-08-05 13:14:15")) // true
carbon.Parse("2020-08-05 13:14:15").Eq(carbon.Parse("2020-08-05 13:14:00")) // false
carbon.Parse("2020-08-05 13:14:15").Compare("=", carbon.Parse("2020-08-05 13:14:15")) // true
carbon.Parse("2020-08-05 13:14:15").Compare("=", carbon.Parse("2020-08-05 13:14:00")) // false

// Whether not equal
carbon.Parse("2020-08-05 13:14:15").Ne(carbon.Parse("2020-08-06 13:14:15")) // true
carbon.Parse("2020-08-05 13:14:15").Ne(carbon.Parse("2020-08-05 13:14:15")) // false
carbon.Parse("2020-08-05 13:14:15").Compare("!=", carbon.Parse("2020-08-06 13:14:15")) // true
carbon.Parse("2020-08-05 13:14:15").Compare("<>", carbon.Parse("2020-08-05 13:14:15")) // false

// Whether greater than or equal
carbon.Parse("2020-08-05 13:14:15").Gte(carbon.Parse("2020-08-04 13:14:15")) // true
carbon.Parse("2020-08-05 13:14:15").Gte(carbon.Parse("2020-08-05 13:14:15")) // true
carbon.Parse("2020-08-05 13:14:15").Compare(">=", carbon.Parse("2020-08-04 13:14:15")) // true
carbon.Parse("2020-08-05 13:14:15").Compare(">=", carbon.Parse("2020-08-05 13:14:15")) // true

// Whether less than or equal
carbon.Parse("2020-08-05 13:14:15").Lte(carbon.Parse("2020-08-06 13:14:15")) // true
carbon.Parse("2020-08-05 13:14:15").Lte(carbon.Parse("2020-08-05 13:14:15")) // true
carbon.Parse("2020-08-05 13:14:15").Compare("<=", carbon.Parse("2020-08-06 13:14:15")) // true
carbon.Parse("2020-08-05 13:14:15").Compare("<=", carbon.Parse("2020-08-05 13:14:15")) // true

// Whether between two Carbon instances, excluded the start and end Carbon instance
carbon.Parse("2020-08-05 13:14:15").Between(carbon.Parse("2020-08-05 13:14:15"), carbon.Parse("2020-08-06 13:14:15")) // false
carbon.Parse("2020-08-05 13:14:15").Between(carbon.Parse("2020-08-04 13:14:15"), carbon.Parse("2020-08-06 13:14:15")) // true

// Whether between two Carbon instances, included the start Carbon instance
carbon.Parse("2020-08-05 13:14:15").BetweenIncludedStart(carbon.Parse("2020-08-05 13:14:15"), carbon.Parse("2020-08-06 13:14:15")) // true
carbon.Parse("2020-08-05 13:14:15").BetweenIncludedStart(carbon.Parse("2020-08-04 13:14:15"), carbon.Parse("2020-08-06 13:14:15")) // true

// Whether between two Carbon instances, included the end Carbon instance
carbon.Parse("2020-08-05 13:14:15").BetweenIncludedEnd(carbon.Parse("2020-08-04 13:14:15"), carbon.Parse("2020-08-05 13:14:15")) // true
carbon.Parse("2020-08-05 13:14:15").BetweenIncludedEnd(carbon.Parse("2020-08-04 13:14:15"), carbon.Parse("2020-08-06 13:14:15")) // true

// Whether between two Carbon instances, included the start and end Carbon instance
carbon.Parse("2020-08-05 13:14:15").BetweenIncludedBoth(carbon.Parse("2020-08-05 13:14:15"), carbon.Parse("2020-08-06 13:14:15")) // true
carbon.Parse("2020-08-05 13:14:15").BetweenIncludedBoth(carbon.Parse("2020-08-04 13:14:15"), carbon.Parse("2020-08-05 13:14:15")) // true

For the definition of long year, please see https://en.wikipedia.org/wiki/ISO_8601#Week_dates

Setter
// Set timezone
carbon.SetTimezone(carbon.PRC).Now().ToDateTimeString() // 2020-08-05 13:14:15
carbon.SetTimezone(carbon.Tokyo).Now().ToDateTimeString() // 2020-08-05 14:14:15
carbon.SetTimezone(carbon.Tokyo).Now().SetTimezone(carbon.PRC).ToDateTimeString() // 2020-08-05 12:14:15

// Set locale
carbon.Parse("2020-07-05 13:14:15").SetLocale("en").DiffForHumans() // 1 month before
carbon.Parse("2020-07-05 13:14:15").SetLocale("zh-CN").DiffForHumans() // 1 月前

// Set year, month, day, hour, minute and second.
carbon.Parse("2020-01-01").SetDateTime(2019, 2, 2, 13, 14, 15).ToString() // 2019-02-02 13:14:15 +0800 CST
carbon.Parse("2020-01-01").SetDateTime(2019, 2, 31, 13, 14, 15).ToString() // 2019-03-03 13:14:15 +0800 CST
// Set year, month, day, hour, minute and second with millisecond.
carbon.Parse("2020-01-01").SetDateTimeMilli(2019, 2, 2, 13, 14, 15, 999).ToString() // 2019-02-02 13:14:15.999 +0800 CST
carbon.Parse("2020-01-01").SetDateTimeMilli(2019, 2, 31, 13, 14, 15, 999).ToString() // 2019-03-03 13:14:15.999 +0800 CST
// Set year, month, day, hour, minute and second with microsecond.
carbon.Parse("2020-01-01").SetDateTimeMicro(2019, 2, 2, 13, 14, 15, 999999).ToString() // 2019-02-02 13:14:15.999999 +0800 CST
carbon.Parse("2020-01-01").SetDateTimeMicro(2019, 2, 31, 13, 14, 15, 999999).ToString() // 2019-03-03 13:14:15.999999 +0800 CST
// Set year, month, day, hour, minute and second with nanosecond.
carbon.Parse("2020-01-01").SetDateTimeNano(2019, 2, 2, 13, 14, 15, 999999999).ToString() // 2019-02-02 13:14:15.999999999 +0800 CST
carbon.Parse("2020-01-01").SetDateTimeNano(2019, 2, 31, 13, 14, 15, 999999999).ToString() // 2019-03-03 13:14:15.999999999 +0800 CST

// Set year, month and day.
carbon.Parse("2020-01-01").SetDate(2019, 2, 2).ToDateTimeString() // 2019-02-02 00:00:00
carbon.Parse("2020-01-01").SetDate(2019, 2, 31).ToDateTimeString() // 2019-03-03 00:00:00

// Set hour, minute and second.
carbon.Parse("2020-01-01").SetTime(13, 14, 15).ToDateTimeString() // 2020-01-01 13:14:15
carbon.Parse("2020-01-01").SetTime(13, 14, 90).ToDateTimeString() // 2020-01-01 13:15:30

// Set year
carbon.Parse("2020-02-29").SetYear(2021).ToDateString() // 2021-03-01
// Set year without overflowing month
carbon.Parse("2020-02-29").SetYearNoOverflow(2021).ToDateString() // 2021-02-28

// Set month
carbon.Parse("2020-01-31").SetMonth(2).ToDateString() // 2020-03-02
// Set month without overflowing month
carbon.Parse("2020-01-31").SetMonthNoOverflow(2).ToDateString() // 2020-02-29

// Set start day of the week
carbon.Parse("2020-08-02").SetWeekStartsAt(carbon.Sunday).Week() // 0
carbon.Parse("2020-08-02").SetWeekStartsAt(carbon.Monday).Week() // 6

// Set day
carbon.Parse("2019-08-05").SetDay(31).ToDateString() // 2020-08-31
carbon.Parse("2020-02-01").SetDay(31).ToDateString() // 2020-03-02

// Set hour
carbon.Parse("2020-08-05 13:14:15").SetHour(10).ToDateTimeString() // 2020-08-05 10:14:15
carbon.Parse("2020-08-05 13:14:15").SetHour(24).ToDateTimeString() // 2020-08-06 00:14:15

// Set minute
carbon.Parse("2020-08-05 13:14:15").SetMinute(10).ToDateTimeString() // 2020-08-05 13:10:15
carbon.Parse("2020-08-05 13:14:15").SetMinute(60).ToDateTimeString() // 2020-08-05 14:00:15

// Set second
carbon.Parse("2020-08-05 13:14:15").SetSecond(10).ToDateTimeString() // 2020-08-05 13:14:10
carbon.Parse("2020-08-05 13:14:15").SetSecond(60).ToDateTimeString() // 2020-08-05 13:15:00

// Set millisecond
carbon.Parse("2020-08-05 13:14:15").SetMillisecond(100).Millisecond() // 100
carbon.Parse("2020-08-05 13:14:15").SetMillisecond(999).Millisecond() // 999

// Set microsecond
carbon.Parse("2020-08-05 13:14:15").SetMicrosecond(100000).Microsecond() // 100000
carbon.Parse("2020-08-05 13:14:15").SetMicrosecond(999999).Microsecond() // 999999

// Set nanosecond
carbon.Parse("2020-08-05 13:14:15").SetNanosecond(100000000).Nanosecond() // 100000000
carbon.Parse("2020-08-05 13:14:15").SetNanosecond(999999999).Nanosecond() // 999999999
Getter
// Get total days of the year
carbon.Parse("2019-08-05 13:14:15").DaysInYear() // 365
carbon.Parse("2020-08-05 13:14:15").DaysInYear() // 366
// Get total days of the month
carbon.Parse("2020-02-01 13:14:15").DaysInMonth() // 29
carbon.Parse("2020-04-01 13:14:15").DaysInMonth() // 30
carbon.Parse("2020-08-01 13:14:15").DaysInMonth() // 31

// Get day of the year
carbon.Parse("2020-08-05 13:14:15").DayOfYear() // 218
// Get week of the year
carbon.Parse("2020-08-05 13:14:15").WeekOfYear() // 32
// Get day of the month
carbon.Parse("2020-08-05 13:14:15").DayOfMonth() // 5
// Get week of the month
carbon.Parse("2020-08-05 13:14:15").WeekOfMonth() // 1
// Get day of the week
carbon.Parse("2020-08-05 13:14:15").DayOfWeek() // 3

// Get current year, month, day, hour, minute and second
carbon.Parse("2020-08-05 13:14:15").DateTime() // 2020,8,5,13,14,15
// Get current year, month, day, hour, minute, second and millisecond
carbon.Parse("2020-08-05 13:14:15").DateTimeMilli() // 2020,8,5,13,14,15,999
// Get current year, month, day, hour, minute, second and microsecond
carbon.Parse("2020-08-05 13:14:15").DateTimeMicro() // 2020,8,5,13,14,15,999999
// Get current year, month, day, hour, minute, second and nanosecond
carbon.Parse("2020-08-05 13:14:15").DateTimeNano() // 2020,8,5,13,14,15,999999999

// Get current year, month and day
carbon.Parse("2020-08-05 13:14:15.999999999").Date() // 2020,8,5
// Get current year, month, day and millisecond
carbon.Parse("2020-08-05 13:14:15.999999999").DateMilli() // 2020,8,5,999
// Get current year, month, day and microsecond
carbon.Parse("2020-08-05 13:14:15.999999999").DateMicro() // 2020,8,5,999999
// Get current year, month, day and nanosecond
carbon.Parse("2020-08-05 13:14:15.999999999").DateNano() // 2020,8,5,999999999

// Get current hour, minute and second
carbon.Parse("2020-08-05 13:14:15.999999999").Time() // 13,14,15
// Get current hour, minute ,second and millisecond
carbon.Parse("2020-08-05 13:14:15.999999999").TimeMilli() // 13,14,15,999
// Get current hour, minute ,second and microsecond
carbon.Parse("2020-08-05 13:14:15.999999999").TimeMicro() // 13,14,15,999999
// Get current hour, minute ,second and nanosecond
carbon.Parse("2020-08-05 13:14:15.999999999").TimeNano() // 13,14,15,999999999

// Get current century
carbon.Parse("2020-08-05 13:14:15").Century() // 21
// Get current decade
carbon.Parse("2019-08-05 13:14:15").Decade() // 10
carbon.Parse("2021-08-05 13:14:15").Decade() // 20
// Get current year
carbon.Parse("2020-08-05 13:14:15").Year() // 2020
// Get current quarter
carbon.Parse("2020-08-05 13:14:15").Quarter() // 3
// Get current month
carbon.Parse("2020-08-05 13:14:15").Month() // 8
// Get current week(start from 0)
carbon.Parse("2020-08-02 13:14:15").Week() // 0
carbon.Parse("2020-08-02").SetWeekStartsAt(carbon.Sunday).Week() // 0
carbon.Parse("2020-08-02").SetWeekStartsAt(carbon.Monday).Week() // 6
// Get current day
carbon.Parse("2020-08-05 13:14:15").Day() // 5
// Get current hour
carbon.Parse("2020-08-05 13:14:15").Hour() // 13
// Get current minute
carbon.Parse("2020-08-05 13:14:15").Minute() // 14
// Get current second
carbon.Parse("2020-08-05 13:14:15").Second() // 15
// Get current millisecond
carbon.Parse("2020-08-05 13:14:15.999").Millisecond() // 999
// Get current microsecond
carbon.Parse("2020-08-05 13:14:15.999").Microsecond() // 999000
// Get current nanosecond
carbon.Parse("2020-08-05 13:14:15.999").Nanosecond() // 999000000

// Get timestamp with second
carbon.Parse("2020-08-05 13:14:15").Timestamp() // 1596604455
// Get timestamp with millisecond
carbon.Parse("2020-08-05 13:14:15").TimestampMilli() // 1596604455000
// Get timestamp with microsecond
carbon.Parse("2020-08-05 13:14:15").TimestampMicro() // 1596604455000000
// Get timestamp with nanosecond
carbon.Parse("2020-08-05 13:14:15").TimestampNano() // 1596604455000000000

// Get timezone name
carbon.SetTimezone(carbon.PRC).Timezone() // CST
carbon.SetTimezone(carbon.Tokyo).Timezone() // JST

// Get location name
carbon.SetTimezone(carbon.PRC).Location() // PRC
carbon.SetTimezone(carbon.Tokyo).Location() // Asia/Tokyo

// Get offset seconds from the UTC timezone
carbon.SetTimezone(carbon.PRC).Offset() // 28800
carbon.SetTimezone(carbon.Tokyo).Offset() // 32400

// Get locale name
carbon.Now().SetLocale("en").Locale() // en
carbon.Now().SetLocale("zh-CN").Locale() // zh-CN

// Get constellation name
carbon.Now().Constellation() // Leo
carbon.Now().SetLocale("en").Constellation() // Leo
carbon.Now().SetLocale("zh-CN").Constellation() // 狮子座

// Get season name
carbon.Now().Season() // Summer
carbon.Now().SetLocale("en").Season() // Summer
carbon.Now().SetLocale("zh-CN").Season() // 夏季

// Get current age
carbon.Parse("2002-01-01 13:14:15").Age() // 17
carbon.Parse("2002-12-31 13:14:15").Age() // 18
Output
// Output a string in date and time format
carbon.Parse("2020-08-05 13:14:15").ToDateTimeString() // 2020-08-05 13:14:15
// Output a string in date and time with millisecond format
carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToDateTimeMilliString() // 2020-08-05 13:14:15.999
// Output a string in date and time with microsecond format
carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToDateTimeMicroString() // 2020-08-05 13:14:15.999999
// Output a string in date and time with nanosecond format
carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToDateTimeNanoString() // 2020-08-05 13:14:15.999999999

// Output a string in short date and time format
carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToShortDateTimeString() // 20200805131415
// Output a string in short date and time with millisecond format
carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToShortDateTimeMilliString() // 20200805131415.999
// Output a string in short date and time with microsecond format
carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToShortDateTimeMicroString() // 20200805131415.999999
// Output a string in short date and time with nanosecond format
carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToShortDateTimeNanoString() // 20200805131415.999999999

// Output a in date format
carbon.Parse("2020-08-05 13:14:15.999999999").ToDateString() // 2020-08-05
// Output a in date with millisecond format
carbon.Parse("2020-08-05 13:14:15.999999999").ToDateMilliString() // 2020-08-05.999
// Output a in date with microsecond format
carbon.Parse("2020-08-05 13:14:15.999999999").ToDateMicroString() // 2020-08-05.999999
// Output a in date with nanosecond format
carbon.Parse("2020-08-05 13:14:15.999999999").ToDateNanoString() // 2020-08-05.999999999

// Output a string in short date format
carbon.Parse("2020-08-05 13:14:15.999999999").ToShortDateString() // 20200805
// Output a string in short date with millisecond format
carbon.Parse("2020-08-05 13:14:15.999999999").ToShortDateMilliString() // 20200805.999
// Output a string in short date with microsecond format
carbon.Parse("2020-08-05 13:14:15.999999999").ToShortDateMicroString() // 20200805.999999
// Output a string in short date with nanosecond format
carbon.Parse("2020-08-05 13:14:15.999999999").ToShortDateNanoString() // 20200805.999999999

// Output a string in time format
carbon.Parse("2020-08-05 13:14:15.999999999").ToTimeString() // 13:14:15
// Output a string in time with millisecond format
carbon.Parse("2020-08-05 13:14:15.999999999").ToTimeMilliString() // 13:14:15.999
// Output a string in time with microsecond format
carbon.Parse("2020-08-05 13:14:15.999999999").ToTimeMicroString() // 13:14:15.999999
// Output a string in time with nanosecond format
carbon.Parse("2020-08-05 13:14:15.999999999").ToTimeNanoString() // 13:14:15.999999999

// Output a string in short time format
carbon.Parse("2020-08-05 13:14:15.999999999").ToShortTimeString() // 131415
// Output a string in short time with millisecond format
carbon.Parse("2020-08-05 13:14:15.999999999").ToShortTimeMilliString() // 131415.999
// Output a string in short time with microsecond format
carbon.Parse("2020-08-05 13:14:15.999999999").ToShortTimeMicroString() // 131415.999999
// Output a string in short time with nanosecond format
carbon.Parse("2020-08-05 13:14:15.999999999").ToShortTimeNanoString() // 131415.999999999

// Output a string in ANSIC format
carbon.Parse("2020-08-05 13:14:15").ToANSICString() // Wed Aug  5 13:14:15 2020
// Output a string in Atom format
carbon.Parse("2020-08-05 13:14:15").ToAtomString() // 2020-08-05T13:14:15+08:00
// Output a string in unix date format
carbon.Parse("2020-08-05 13:14:15").ToUnixDateString() // Wed Aug  5 13:14:15 CST 2020
// Output a string in ruby date format
carbon.Parse("2020-08-05 13:14:15").ToRubyDateString() // Wed Aug 05 13:14:15 +0800 2020
// Output a string in Kitchen format
carbon.Parse("2020-08-05 13:14:15").ToKitchenString() // 1:14PM
// Output a string in Cookie format
carbon.Parse("2020-08-05 13:14:15").ToCookieString() // Wednesday, 05-Aug-2020 13:14:15 CST
// Output a string in day, date and time format
carbon.Parse("2020-08-05 13:14:15").ToDayDateTimeString() // Wed, Aug 5, 2020 1:14 PM
// Output a string in RSS format
carbon.Parse("2020-08-05 13:14:15").ToRssString() // Wed, 05 Aug 2020 13:14:15 +0800
// Output a string in W3C format
carbon.Parse("2020-08-05 13:14:15").ToW3cString() // 2020-08-05T13:14:15+08:00

// Output a string in ISO8601 format
carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601String() // 2020-08-05T13:14:15+08:00
// Output a string in ISO8601 with millisecond format
carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601MilliString() // 2020-08-05T13:14:15.999+08:00
// Output a string in ISO8601 with microsecond format
carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601MicroString() // 2020-08-05T13:14:15.999999+08:00
// Output a string in ISO8601 with nanosecond format
carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601NanoString() // 2020-08-05T13:14:15.999999999+08:00

// Output a string in RFC822 format
carbon.Parse("2020-08-05 13:14:15").ToRfc822String() // 05 Aug 20 13:14 CST
// Output a string in RFC822Z format
carbon.Parse("2020-08-05 13:14:15").ToRfc822zString() // 05 Aug 20 13:14 +0800
// Output a string in RFC850 format
carbon.Parse("2020-08-05 13:14:15").ToRfc850String() // Wednesday, 05-Aug-20 13:14:15 CST
// Output a string in RFC1036 format
carbon.Parse("2020-08-05 13:14:15").ToRfc1036String() // Wed, 05 Aug 20 13:14:15 +0800
// Output a string in RFC1123 format
carbon.Parse("2020-08-05 13:14:15").ToRfc1123String() // Wed, 05 Aug 2020 13:14:15 CST
// Output a string in RFC1123Z format
carbon.Parse("2020-08-05 13:14:15").ToRfc1123zString() // Wed, 05 Aug 2020 13:14:15 +0800
// Output a string in RFC2822 format
carbon.Parse("2020-08-05 13:14:15").ToRfc2822String() // Wed, 05 Aug 2020 13:14:15 +0800
// Output a string in RFC7231 format
carbon.Parse("2020-08-05 13:14:15").ToRfc7231String() // Wed, 05 Aug 2020 13:14:15 GMT

// Output a string in RFC3339 format
carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToRfc3339String() // 2020-08-05T13:14:15+08:00
// Output a string in RFC3339 with millisecond format
carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToRfc3339MilliString() // 2020-08-05T13:14:15.999+08:00
// Output a string in RFC3339 with microsecond format
carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToRfc3339MicroString() // 2020-08-05T13:14:15.999999+08:00
// Output a string in RFC3339 with nanosecond format
carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToRfc3339NanoString() // 2020-08-05T13:14:15.999999999+08:00

// Output a string in date and time format
fmt.Sprintf("%s", carbon.Parse("2020-08-05 13:14:15")) // 2020-08-05 13:14:15

// Output a string in "2006-01-02 15:04:05.999999999 -0700 MST" format
carbon.Parse("2020-08-05 13:14:15").ToString() // 2020-08-05 13:14:15.999999 +0800 CST

// Output a string by layout, Layout() is shorthand for ToLayoutString()
carbon.Parse("2020-08-05 13:14:15").Layout(carbon.ISO8601Layout) // 2020-08-05T13:14:15+08:00
carbon.Parse("2020-08-05 13:14:15").Layout("20060102150405") // 20200805131415
carbon.Parse("2020-08-05 13:14:15").Layout("2006年01月02日 15时04分05秒") // 2020年08月05日 13时14分15秒
carbon.Parse("2020-08-05 13:14:15").Layout("It is 2006-01-02 15:04:05") // It is 2020-08-05 13:14:15

// Output a string by format, Format() is shorthand for ToFormatString()
carbon.Parse("2020-08-05 13:14:15").Format("YmdHis") // 20200805131415
carbon.Parse("2020-08-05 13:14:15").Format("Y年m月d日 H时i分s秒") // 2020年08月05日 13时14分15秒
carbon.Parse("2020-08-05 13:14:15").Format("l jS \\o\\f F Y h:i:s A") // Wednesday 5th of August 2020 01:14:15 PM
carbon.Parse("2020-08-05 13:14:15").Format("\\I\\t \\i\\s Y-m-d H:i:s") // It is 2020-08-05 13:14:15

For more supported format signs, please see the Format sign table

Constellation
// Get constellation name
carbon.Parse("2020-08-05 13:14:15").Constellation() // Leo

// Whether is Aries
carbon.Parse("2020-08-05 13:14:15").IsAries() // false
// Whether is Taurus
carbon.Parse("2020-08-05 13:14:15").IsTaurus() // false
// Whether is Gemini
carbon.Parse("2020-08-05 13:14:15").IsGemini() // false
// Whether is Cancer
carbon.Parse("2020-08-05 13:14:15").IsCancer() // false
// Whether is Leo
carbon.Parse("2020-08-05 13:14:15").IsLeo() // true
// Whether is Virgo
carbon.Parse("2020-08-05 13:14:15").IsVirgo() // false
// Whether is Libra
carbon.Parse("2020-08-05 13:14:15").IsLibra() // false
// Whether is Scorpio
carbon.Parse("2020-08-05 13:14:15").IsScorpio() // false
// Whether is Sagittarius
carbon.Parse("2020-08-05 13:14:15").IsSagittarius() // false
// Whether is Capricorn
carbon.Parse("2020-08-05 13:14:15").IsCapricorn() // false
// Whether is Aquarius
carbon.Parse("2020-08-05 13:14:15").IsAquarius() // false
// Whether is Pisces
carbon.Parse("2020-08-05 13:14:15").IsPisces() // false
Season

According to the meteorological division method, March to May is spring, June to August is summer, September to November is autumn, and December to February is winter

// Get season name
carbon.Parse("2020-08-05 13:14:15").Season() // Summer

// Start of the season
carbon.Parse("2020-08-05 13:14:15").StartOfSeason().ToDateTimeString() // 2020-06-01 00:00:00
// End of the season
carbon.Parse("2020-08-05 13:14:15").EndOfSeason().ToDateTimeString() // 2020-08-31 23:59:59

// Whether is spring
carbon.Parse("2020-08-05 13:14:15").IsSpring() // false
// Whether is summer
carbon.Parse("2020-08-05 13:14:15").IsSummer() // true
// Whether is autumn
carbon.Parse("2020-08-05 13:14:15").IsAutumn() // false
// Whether is winter
carbon.Parse("2020-08-05 13:14:15").IsWinter() // false
Chinese Lunar

Currently only 200 years from 1900 to 2100 are supported

// Get Chinese Lunar year of animal
carbon.Parse("2020-08-05 13:14:15").Lunar().Animal() // 鼠

// Get Chinese lunar festival
carbon.Parse("2021-02-12 13:14:15").Lunar().Festival() // 春节

// Get Chinese lunar year, month, day, hour, minute and second
carbon.Parse("2020-08-05 13:14:15").Lunar().DateTime() // 2020, 6, 16, 13, 14, 15
// Get Chinese lunar year, month and day
carbon.Parse("2020-08-05 13:14:15").Lunar().Date() // 2020, 6, 16
// Get Chinese lunar hour, minute and second
carbon.Parse("2020-08-05 13:14:15").Lunar().Time() // 13, 14, 15

// Get Chinese lunar year
carbon.Parse("2020-08-05 13:14:15").Lunar().Year() // 2020
// Get Chinese lunar month
carbon.Parse("2020-08-05 13:14:15").Lunar().Month() // 6
// Get Chinese lunar leap month
carbon.Parse("2020-08-05 13:14:15").Lunar().LeapMonth() // 4
// Get Chinese lunar day
carbon.Parse("2020-08-05 13:14:15").Lunar().Day() // 16
// Get Chinese lunar date as string in YYYY-MM-DD HH::ii::ss format
fmt.Sprintf("%s", carbon.Parse("2020-08-05 13:14:15").Lunar()) // 2020-06-16 13:14:15

// Get Chinese lunar year as string
carbon.Parse("2020-08-05 13:14:15").Lunar().ToYearString() // 二零二零
// Get Chinese lunar month as string
carbon.Parse("2020-08-05 13:14:15").Lunar().ToMonthString() // 六月
// Get Chinese lunar day as string
carbon.Parse("2020-08-05 13:14:15").Lunar().ToDayString() // 十六
// Get Chinese lunar date as string
carbon.Parse("2020-08-05 13:14:15").Lunar().ToDateString() // 二零二零年六月十六

// Whether is a leap year
carbon.Parse("2020-08-05 13:14:15").Lunar().IsLeapYear() // true
// Whether is a leap month
carbon.Parse("2020-08-05 13:14:15").Lunar().IsLeapMonth() // false

// Whether is a year of the rat
carbon.Parse("2020-08-05 13:14:15").Lunar().IsRatYear() // true
// Whether is a year of the ox
carbon.Parse("2020-08-05 13:14:15").Lunar().IsOxYear() // false
// Whether is a year of the tiger
carbon.Parse("2020-08-05 13:14:15").Lunar().IsTigerYear() // false
// Whether is a year of the rabbit
carbon.Parse("2020-08-05 13:14:15").Lunar().IsRabbitYear() // false
// Whether is a year of the dragon
carbon.Parse("2020-08-05 13:14:15").Lunar().IsDragonYear() // false
// Whether is a year of the snake
carbon.Parse("2020-08-05 13:14:15").Lunar().IsSnakeYear() // false
// Whether is a year of the horse
carbon.Parse("2020-08-05 13:14:15").Lunar().IsHorseYear() // false
// Whether is a year of the goat
carbon.Parse("2020-08-05 13:14:15").Lunar().IsGoatYear() // false
// Whether is a year of the monkey
carbon.Parse("2020-08-05 13:14:15").Lunar().IsMonkeyYear() // false
// Whether is a year of the rooster
carbon.Parse("2020-08-05 13:14:15").Lunar().IsRoosterYear() // false
// Whether is a year of the dog
carbon.Parse("2020-08-05 13:14:15").Lunar().IsDogYear() // false
// Whether is a year of the dig
carbon.Parse("2020-08-05 13:14:15").Lunar().IsPigYear() // false

// Get Chinese double-hour
carbon.Parse("2020-02-05 21:00:00").Lunar().DoubleHour() // 亥时

// Whether is FirstDoubleHour
carbon.Parse("2020-03-21 00:00:00").Lunar().IsFirstDoubleHour() // true
// Whether is SecondDoubleHour
carbon.Parse("2020-03-21 01:00:00").Lunar().IsSecondDoubleHour() // true
// Whether is ThirdDoubleHour
carbon.Parse("2020-03-21 03:00:00").Lunar().IsThirdDoubleHour() // true
// Whether is FourthDoubleHour
carbon.Parse("2020-03-21 05:00:00").Lunar().IsFourthDoubleHour() // true
// Whether is FifthDoubleHour
carbon.Parse("2020-03-21 07:00:00").Lunar().IsFifthDoubleHour() // true
// Whether is SixthDoubleHour
carbon.Parse("2020-03-21 09:00:00").Lunar().IsSixthDoubleHour() // true
// Whether is SeventhDoubleHour
carbon.Parse("2020-03-21 11:00:00").Lunar().IsSeventhDoubleHour() // true
// Whether is EighthDoubleHour
carbon.Parse("2020-03-21 13:00:00").Lunar().IsEighthDoubleHour() // true
// Whether is NinthDoubleHour
carbon.Parse("2020-03-21 15:00:00").Lunar().IsNinthDoubleHour() // true
// Whether is TenthDoubleHour
carbon.Parse("2020-03-21 17:00:00").Lunar().IsTenthDoubleHour() // true
// Whether is EleventhDoubleHour
carbon.Parse("2020-03-21 19:00:00").Lunar().IsEleventhDoubleHour() // true
// Whether is TwelfthDoubleHour
carbon.Parse("2020-03-21 21:00:00").Lunar().IsTwelfthDoubleHour() // true
JSON handling
Define model
type Person struct {
    Name string `json:"name"`
    Age int `json:"age"`
    Birthday carbon.DateTime `json:"birthday"`
    GraduatedAt carbon.Date `json:"graduated_at"`
    DateTime1 carbon.Timestamp `json:"date_time1"`
    DateTime2 carbon.TimestampMilli `json:"date_time2"`
    DateTime3 carbon.TimestampMicro `json:"date_time3"`
    DateTime4 carbon.TimestampNano `json:"date_time4"`
}
Instantiate model
person := Person {
	Name:        "gouguoyin",
	Age:         18,
	Birthday:    carbon.DateTime{carbon.Now().SubYears(18)},
	GraduatedAt: carbon.Date{carbon.Parse("2020-08-05 13:14:15")},
	DateTime1:   carbon.Timestamp{carbon.Parse("2023-08-05 13:14:15")},
	DateTime2:   carbon.TimestampMilli{carbon.Parse("2024-08-05 13:14:15")},
	DateTime3:   carbon.TimestampMicro{carbon.Parse("2025-08-05 13:14:15")},
	DateTime4:   carbon.TimestampNano{carbon.Parse("2025-08-05 13:14:15")},
}
JSON encode
data, err := json.Marshal(&person)
if err != nil {
    // Error handle...
    log.Fatal(err)
}
fmt.Printf("%s", data)
// Output
{
    "name": "gouguoyin",
    "age": 18,
    "birthday": "2003-07-16 16:22:02",
    "graduated_at": "2020-08-05",
    "date_time1": 1691212455,
    "date_time2": 1722834855000,
    "date_time3": 1754370855000000,
    "date_time4": 1754370855000000000
}
JSON decode
str := `{
	"name": "gouguoyin",
	"age": 18,
	"birthday": "2003-07-16 16:22:02",
	"graduated_at": "2020-08-05",
	"date_time1": 1691212455,
	"date_time2": 1722834855000,
	"date_time3": 1754370855000000,
	"date_time4": 1754370855000000000
}`
person := new(Person)
err := json.Unmarshal([]byte(str), &person)
if err != nil {
    // Error handle...
    log.Fatal(err)
}
fmt.Printf("%+v", *person)
// Output
{Name:gouguoyin Age:18 Birthday:2003-07-16 16:22:02 GraduatedAt:2020-08-05 00:00:00 DateTime1:2023-08-05 13:14:15 DateTime2:2024-08-05 13:14:15 DateTime3:2025-08-05 13:14:15 DateTime4:2025-08-05 13:14:15}
I18n

The following languages are supported

The following methods are supported

  • Constellation():get constellation name
  • Season():get season name
  • DiffForHumans():get the difference in human-readable format
  • ToMonthString():output a string in month format
  • ToShortMonthString():output a string in short month format
  • ToWeekString():output a string in week format
  • ToShortWeekString():output a string in short week format
Set locale
lang := carbon.NewLanguage()
lang.SetLocale("en")

c := carbon.SetLanguage(lang)
    if c.Error != nil {
    // Error handle...
    log.Fatal(err)
}

c.Now().AddHours(1).DiffForHumans() // 1 hour from now
c.Now().AddHours(1).ToMonthString() // August
c.Now().AddHours(1).ToShortMonthString() // Aug
c.Now().AddHours(1).ToWeekString() // Wednesday
c.Now().AddHours(1).ToShortWeekString() // Wed
c.Now().AddHours(1).Constellation() // Leo
c.Now().AddHours(1).Season() // Summer
Reset some resources(the rests still translate from the given locale)
lang := carbon.NewLanguage()
lang.SetLocale("en")

resources := map[string]string {
    "hour": "%dh",
}
lang.SetResources(resources)

c := carbon.SetLanguage(lang)
if c.Error != nil {
	// Error handle...
	log.Fatal(err)
}

c.Now().AddYears(1).DiffForHumans() // 1 year from now
c.Now().AddHours(1).DiffForHumans() // 1h from now
c.Now().ToMonthString() // August
c.Now().ToShortMonthString() // Aug
c.Now().ToWeekString() // Tuesday
c.Now().ToShortWeekString() // Tue
c.Now().Constellation() // Leo
c.Now().Season() // Summer
Reset all resources
lang := carbon.NewLanguage()
resources := map[string]string {
	"months": "january|february|march|april|may|june|july|august|september|october|november|december",
	"short_months": "jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec",
	"weeks": "sunday|monday|tuesday|wednesday|thursday|friday|saturday",
	"short_weeks": "sun|mon|tue|wed|thu|fri|sat",
	"seasons": "spring|summer|autumn|winter",
	"constellations": "aries|taurus|gemini|cancer|leo|virgo|libra|scorpio|sagittarius|capricornus|aquarius|pisce",
	"year": "1 yr|%d yrs",
	"month": "1 mo|%d mos",
	"week": "%dw",
	"day": "%dd",
	"hour": "%dh",
	"minute": "%dm",
	"second": "%ds",
	"now": "just now",
	"ago": "%s ago",
	"from_now": "in %s",
	"before": "%s before",
	"after": "%s after",
}
lang.SetResources(resources)

c := carbon.SetLanguage(lang)
c.Now().AddYears(1).DiffForHumans() // in 1 yr
c.Now().AddHours(1).DiffForHumans() // in 1h
c.Now().ToMonthString() // august
c.Now().ToShortMonthString() // aug
c.Now().ToWeekString() // tuesday
c.Now().ToShortWeekString() // tue
c.Now().Constellation() // leo
c.Now().Season() // summer
Error handling

If more than one error occurs, only the first error is returned

Scene one
c := carbon.SetTimezone(PRC).Parse("xxx")
if c.Error != nil {
    // Error handle...
    log.Fatal(c.Error)
}
fmt.Println(c.ToDateTimeString())
// Output
cannot parse "xxx" as carbon, please make sure the value is valid
Scene two
c := carbon.SetTimezone("xxx").Parse("2020-08-05")
if c.Error != nil {
    // Error handle...
    log.Fatal(c.Error)
}
fmt.Println(c.ToDateTimeString())
// Output
invalid timezone "xxx", please see the file "$GOROOT/lib/time/zoneinfo.zip" for all valid timezones
Scene three
c := carbon.SetTimezone("xxx").Parse("12345678")
if c.Error != nil {
    // Error handle...
    log.Fatal(c.Error)
}
fmt.Println(c.ToDateTimeString())
// Output
invalid timezone "xxx", please see the file "$GOROOT/lib/time/zoneinfo.zip" for all valid timezones
Appendix
sign desc length range example
d Day of the month, padded to 2 2 01-31 02
D Day of the week, as an abbreviate localized string 3 Mon-Sun Mon
j Day of the month, no padding - 1-31 2
S English ordinal suffix for the day of the month, 2 characters. Eg: st, nd, rd or th. Works well with j 2 st/nd/rd/th th
l Day of the week, as an unabbreviated localized string - Monday-Sunday Monday
F Month as an unabbreviated localized string - January-December January
m Month, padded to 2 2 01-12 01
M Month as an abbreviated localized string 3 Jan-Dec Jan
n Month, no padding - 1-12 1
Y Four-digit year 4 0000-9999 2006
y Two-digit year 2 00-99 06
a Lowercase morning or afternoon sign 2 am/pm pm
A Uppercase morning or afternoon sign 2 AM/PM PM
g Hour in 12-hour time, no padding - 1-12 3
G Hour in 24-hour time, no padding - 0-23 15
h Hour in 12-hour time, padded to 2 2 00-11 03
H Hour in 24-hour time, padded to 2 2 00-23 15
i Minute, padded to 2 2 01-59 04
s Second, padded to 2 2 01-59 05
c ISO8601 date - - 2006-01-02T15:04:05-07:00
r RFC2822 date - - Mon, 02 Jan 2006 15:04:05 -0700
O Difference to Greenwich time (GMT) without colon between hours and minutes - - +0700
P Difference to Greenwich time (GMT) with colon between hours and minutes - - +07:00
T Abbreviated timezone - - MST
W ISO8601 week of the year - 1-52 1
N ISO8601 day of the week 1 1-7 1
L Whether it's a leap year 1 0-1 0
U Unix timestamp in seconds 10 - 1611818268
u Millisecond, padded to 3 3 - 999
w Day of the week 1 0-6 1
t Total days of the month 2 28-31 31
z Day of the year - 0-365 2
e Location - - America/New_York
Q Quarter 1 1-4 1
C Century - 0-99 21
References
Contributors

Thanks to all of the following who contributed to Carbon:

Sponsors

Carbon is a non-commercial open source project. If you want to support Carbon, you can buy a cup of coffee for developer.

Thanks

Carbon had been being developed with GoLand under the free JetBrains Open Source license, I would like to express my thanks here.

JetBrains

Documentation

Overview

Package carbon is a simple, semantic and developer-friendly golang package for datetime.

Index

Constants

View Source
const (
	Local = "Local"
	CET   = "CET"
	EET   = "EET"
	EST   = "EST"
	GMT   = "GMT"
	UTC   = "UTC"
	UCT   = "UCT"
	MST   = "MST"

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

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

timezones constant 时区常量

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

months constant 月份常量

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

weeks constant 星期常量

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秒
)

numbers constant 数字常量

View Source
const (
	ANSICLayout              = time.ANSIC
	UnixDateLayout           = time.UnixDate
	RubyDateLayout           = time.RubyDate
	RFC822Layout             = time.RFC822
	RFC822ZLayout            = time.RFC822Z
	RFC850Layout             = time.RFC850
	RFC1123Layout            = time.RFC1123
	RFC1123ZLayout           = time.RFC1123Z
	RssLayout                = time.RFC1123Z
	KitchenLayout            = time.Kitchen
	RFC2822Layout            = time.RFC1123Z
	CookieLayout             = "Monday, 02-Jan-2006 15:04:05 MST"
	RFC3339Layout            = "2006-01-02T15:04:05Z07:00"
	RFC3339MilliLayout       = "2006-01-02T15:04:05.999Z07:00"
	RFC3339MicroLayout       = "2006-01-02T15:04:05.999999Z07:00"
	RFC3339NanoLayout        = "2006-01-02T15:04:05.999999999Z07:00"
	ISO8601Layout            = "2006-01-02T15:04:05-07:00"
	ISO8601MilliLayout       = "2006-01-02T15:04:05.999-07:00"
	ISO8601MicroLayout       = "2006-01-02T15:04:05.999999-07:00"
	ISO8601NanoLayout        = "2006-01-02T15:04:05.999999999-07:00"
	RFC1036Layout            = "Mon, 02 Jan 06 15:04:05 -0700"
	RFC7231Layout            = "Mon, 02 Jan 2006 15:04:05 GMT"
	DayDateTimeLayout        = "Mon, Jan 2, 2006 3:04 PM"
	DateTimeLayout           = "2006-01-02 15:04:05"
	DateTimeMilliLayout      = "2006-01-02 15:04:05.999"
	DateTimeMicroLayout      = "2006-01-02 15:04:05.999999"
	DateTimeNanoLayout       = "2006-01-02 15:04:05.999999999"
	ShortDateTimeLayout      = "20060102150405"
	ShortDateTimeMilliLayout = "20060102150405.999"
	ShortDateTimeMicroLayout = "20060102150405.999999"
	ShortDateTimeNanoLayout  = "20060102150405.999999999"
	DateLayout               = "2006-01-02"
	DateMilliLayout          = "2006-01-02.999"
	DateMicroLayout          = "2006-01-02.999999"
	DateNanoLayout           = "2006-01-02.999999999"
	ShortDateLayout          = "20060102"
	ShortDateMilliLayout     = "20060102.999"
	ShortDateMicroLayout     = "20060102.999999"
	ShortDateNanoLayout      = "20060102.999999999"
	TimeLayout               = "15:04:05"
	TimeMilliLayout          = "15:04:05.999"
	TimeMicroLayout          = "15:04:05.999999"
	TimeNanoLayout           = "15:04:05.999999999"
	ShortTimeLayout          = "150405"
	ShortTimeMilliLayout     = "150405.999"
	ShortTimeMicroLayout     = "150405.999999"
	ShortTimeNanoLayout      = "150405.999999999"
)

layouts constant 布局模板常量

View Source
const Version = "1.6.5"

Version current version 当前版本号

Variables

This section is empty.

Functions

This section is empty.

Types

type Carbon added in v1.1.1

type Carbon struct {
	Error error
	// contains filtered or unexported fields
}

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

func CreateFromDate added in v1.2.0

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

CreateFromDate creates a Carbon instance from a given date. 从给定的年月日创建 Carbon 实例

func CreateFromDateTime added in v1.2.0

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

CreateFromDateTime creates a Carbon instance from a given date and time. 从给定的年月日时分秒创建 Carbon 实例

func CreateFromDateTimeMicro added in v1.6.0

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

CreateFromDateTimeMicro creates a Carbon instance from a given date and time with microsecond. 从给定的年月日时分秒创建 Carbon 实例,包含微秒

func CreateFromDateTimeMilli added in v1.6.0

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

CreateFromDateTimeMilli creates a Carbon instance from a given date and time with millisecond. 从给定的年月日时分秒创建 Carbon 实例,包含毫秒

func CreateFromDateTimeNano added in v1.6.0

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

CreateFromDateTimeNano creates a Carbon instance from a given date and time with nanosecond. 从给定的年月日时分秒创建 Carbon 实例,包含纳秒

func CreateFromTime added in v1.2.0

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

CreateFromTime creates a Carbon instance from a given time. 从给定的时分秒创建 Carbon 实例

func CreateFromTimestamp added in v1.2.0

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

CreateFromTimestamp creates a Carbon instance from a given timestamp with second. 从给定的秒级时间戳创建 Carbon 实例

func CreateFromTimestampMicro added in v1.6.0

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

CreateFromTimestampMicro creates a Carbon instance from a given timestamp with microsecond. 从给定的微秒级时间戳创建 Carbon 实例

func CreateFromTimestampMilli added in v1.6.0

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

CreateFromTimestampMilli creates a Carbon instance from a given timestamp with millisecond. 从给定的微秒级时间戳创建 Carbon 实例

func CreateFromTimestampNano added in v1.6.0

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

CreateFromTimestampNano creates a Carbon instance from a given timestamp with nanosecond. 从给定的纳秒级时间戳创建 Carbon 实例

func NewCarbon added in v1.3.9

func NewCarbon() Carbon

NewCarbon returns a new Carbon instance. 初始化 Carbon 结构体

func Now added in v1.2.0

func Now(timezone ...string) Carbon

Now returns a Carbon instance for now. 当前

func Parse added in v1.2.0

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

Parse parses a standard string as a Carbon instance. 将标准时间字符串解析成 Carbon 实例

func ParseByFormat added in v1.2.0

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

ParseByFormat parses a string as a Carbon instance by format. 通过格式模板将字符串解析成 carbon 实例

func ParseByLayout added in v1.3.0

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

ParseByLayout parses a string as a Carbon instance by layout. 通过布局模板将字符串解析成 Carbon 实例

func SetLanguage added in v1.3.2

func SetLanguage(lang *Language) Carbon

SetLanguage sets language. 设置语言对象

func SetLocale added in v1.3.2

func SetLocale(locale string) Carbon

SetLocale sets locale. 设置语言区域

func SetTimezone added in v1.2.2

func SetTimezone(name string) Carbon

SetTimezone sets timezone. 设置时区

func Time2Carbon added in v1.3.0

func Time2Carbon(tt time.Time) Carbon

Time2Carbon converts time.Time to Carbon. 将 time.Time 转换成 Carbon

func Tomorrow added in v1.2.0

func Tomorrow(timezone ...string) Carbon

Tomorrow returns a Carbon instance for tomorrow. 明天

func Yesterday added in v1.2.0

func Yesterday(timezone ...string) Carbon

Yesterday returns a Carbon instance for yesterday. 昨天

func (Carbon) AddCenturies added in v1.2.6

func (c Carbon) AddCenturies(centuries int) Carbon

AddCenturies adds some centuries. N个世纪后

func (Carbon) AddCenturiesNoOverflow added in v1.3.0

func (c Carbon) AddCenturiesNoOverflow(centuries int) Carbon

AddCenturiesNoOverflow adds some centuries without overflowing month. N个世纪后(月份不溢出)

func (Carbon) AddCentury added in v1.2.6

func (c Carbon) AddCentury() Carbon

AddCentury adds one century. 1个世纪后

func (Carbon) AddCenturyNoOverflow added in v1.3.0

func (c Carbon) AddCenturyNoOverflow() Carbon

AddCenturyNoOverflow adds one century without overflowing month. 1个世纪后(月份不溢出)

func (Carbon) AddDay added in v1.1.1

func (c Carbon) AddDay() Carbon

AddDay adds one day. 1天后

func (Carbon) AddDays added in v1.1.1

func (c Carbon) AddDays(days int) Carbon

AddDays adds some days. N天后

func (Carbon) AddDecade added in v1.5.2

func (c Carbon) AddDecade() Carbon

AddDecade adds one decade. 1个年代后

func (Carbon) AddDecadeNoOverflow added in v1.5.2

func (c Carbon) AddDecadeNoOverflow() Carbon

AddDecadeNoOverflow adds one decade without overflowing month. 1个年代后(月份不溢出)

func (Carbon) AddDecades added in v1.5.2

func (c Carbon) AddDecades(decades int) Carbon

AddDecades adds some decades. N个年代后

func (Carbon) AddDecadesNoOverflow added in v1.5.2

func (c Carbon) AddDecadesNoOverflow(decades int) Carbon

AddDecadesNoOverflow adds some decades without overflowing month. N个年代后(月份不溢出)

func (Carbon) AddDuration added in v1.2.4

func (c Carbon) AddDuration(duration string) Carbon

AddDuration adds one duration. 按照持续时长字符串增加时间,支持整数/浮点数和符号ns(纳秒)、us(微妙)、ms(毫秒)、s(秒)、m(分钟)、h(小时)的组合

func (Carbon) AddHour added in v1.1.1

func (c Carbon) AddHour() Carbon

AddHour adds one hour. 1小时后

func (Carbon) AddHours added in v1.1.1

func (c Carbon) AddHours(hours int) Carbon

AddHours adds some hours. N小时后

func (Carbon) AddMicrosecond added in v1.6.5

func (c Carbon) AddMicrosecond() Carbon

AddMicrosecond adds one microsecond. 1微秒后

func (Carbon) AddMicroseconds added in v1.6.5

func (c Carbon) AddMicroseconds(microseconds int) Carbon

AddMicroseconds adds some microseconds. N微秒后

func (Carbon) AddMillisecond added in v1.6.5

func (c Carbon) AddMillisecond() Carbon

AddMillisecond adds one millisecond. 1毫秒后

func (Carbon) AddMilliseconds added in v1.6.5

func (c Carbon) AddMilliseconds(milliseconds int) Carbon

AddMilliseconds adds some milliseconds. N毫秒后

func (Carbon) AddMinute added in v1.1.1

func (c Carbon) AddMinute() Carbon

AddMinute adds one minute. 1分钟后

func (Carbon) AddMinutes added in v1.1.1

func (c Carbon) AddMinutes(minutes int) Carbon

AddMinutes adds some minutes. N分钟后

func (Carbon) AddMonth added in v1.1.1

func (c Carbon) AddMonth() Carbon

AddMonth adds one month. 1个月后

func (Carbon) AddMonthNoOverflow added in v1.3.0

func (c Carbon) AddMonthNoOverflow() Carbon

AddMonthNoOverflow adds one month without overflowing month. 1个月后(月份不溢出)

func (Carbon) AddMonths added in v1.1.1

func (c Carbon) AddMonths(months int) Carbon

AddMonths adds some months. N个月后

func (Carbon) AddMonthsNoOverflow added in v1.3.0

func (c Carbon) AddMonthsNoOverflow(months int) Carbon

AddMonthsNoOverflow adds some months without overflowing month. N个月后(月份不溢出)

func (Carbon) AddNanosecond added in v1.6.5

func (c Carbon) AddNanosecond() Carbon

AddNanosecond adds one nanoseconds. 1纳秒后

func (Carbon) AddNanoseconds added in v1.6.5

func (c Carbon) AddNanoseconds(nanoseconds int) Carbon

AddNanoseconds adds some nanoseconds. N纳秒后

func (Carbon) AddQuarter added in v1.2.3

func (c Carbon) AddQuarter() Carbon

AddQuarter adds one quarter 1个季度后

func (Carbon) AddQuarterNoOverflow added in v1.3.0

func (c Carbon) AddQuarterNoOverflow() Carbon

AddQuarterNoOverflow adds one quarter without overflowing month. 1个季度后(月份不溢出)

func (Carbon) AddQuarters added in v1.2.3

func (c Carbon) AddQuarters(quarters int) Carbon

AddQuarters adds some quarters N个季度后

func (Carbon) AddQuartersNoOverflow added in v1.3.0

func (c Carbon) AddQuartersNoOverflow(quarters int) Carbon

AddQuartersNoOverflow adds quarters without overflowing month. N个季度后(月份不溢出)

func (Carbon) AddSecond added in v1.1.1

func (c Carbon) AddSecond() Carbon

AddSecond adds one second. 1秒钟后

func (Carbon) AddSeconds added in v1.1.1

func (c Carbon) AddSeconds(seconds int) Carbon

AddSeconds adds some seconds. N秒钟后

func (Carbon) AddWeek added in v1.1.1

func (c Carbon) AddWeek() Carbon

AddWeek adds one week. 1周后

func (Carbon) AddWeeks added in v1.1.1

func (c Carbon) AddWeeks(weeks int) Carbon

AddWeeks adds some weeks. N周后

func (Carbon) AddYear added in v1.1.1

func (c Carbon) AddYear() Carbon

AddYear adds one year. 1年后

func (Carbon) AddYearNoOverflow added in v1.3.0

func (c Carbon) AddYearNoOverflow() Carbon

AddYearNoOverflow adds one year without overflowing month. 1年后(月份不溢出)

func (Carbon) AddYears added in v1.1.1

func (c Carbon) AddYears(years int) Carbon

AddYears adds some years. N年后

func (Carbon) AddYearsNoOverflow added in v1.3.0

func (c Carbon) AddYearsNoOverflow(years int) Carbon

AddYearsNoOverflow adds some years without overflowing month. N年后(月份不溢出)

func (Carbon) Age added in v1.2.1

func (c Carbon) Age() int

Age gets age like 18. 获取年龄

func (Carbon) Between added in v1.2.4

func (c Carbon) Between(start Carbon, end Carbon) bool

Between reports whether between two times, excluded the start and end time. 是否在两个时间之间(不包括这两个时间)

func (Carbon) BetweenIncludedBoth added in v1.2.4

func (c Carbon) BetweenIncludedBoth(start Carbon, end Carbon) bool

BetweenIncludedBoth reports whether between two times, included the start and end time. 是否在两个时间之间(包括这两个时间)

func (Carbon) BetweenIncludedEnd added in v1.4.5

func (c Carbon) BetweenIncludedEnd(start Carbon, end Carbon) bool

BetweenIncludedEnd reports whether between two times, included the end time. 是否在两个时间之间(包括结束时间)

func (Carbon) BetweenIncludedStart added in v1.4.5

func (c Carbon) BetweenIncludedStart(start Carbon, end Carbon) bool

BetweenIncludedStart reports whether between two times, included the start time. 是否在两个时间之间(包括开始时间)

func (Carbon) Carbon2Time added in v1.3.0

func (c Carbon) Carbon2Time() time.Time

Carbon2Time converts Carbon to time.Time. 将 Carbon 转换成 time.Time

func (Carbon) Century added in v1.3.4

func (c Carbon) Century() int

Century gets current century like 21. 获取当前世纪

func (Carbon) Compare added in v1.2.4

func (c Carbon) Compare(operator string, t Carbon) bool

Compare compares by an operator. 时间比较

func (Carbon) Constellation added in v1.3.4

func (c Carbon) Constellation() string

Constellation gets constellation name like "Aries", i18n is supported. 获取星座,支持i18n

func (Carbon) CreateFromDate added in v1.1.1

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

CreateFromDate creates a Carbon instance from a given date. 从给定的年月日创建 Carbon 实例

func (Carbon) CreateFromDateTime added in v1.1.1

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

CreateFromDateTime creates a Carbon instance from a given date and time. 从给定的年月日时分秒创建 Carbon 实例

func (Carbon) CreateFromDateTimeMicro added in v1.6.0

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

CreateFromDateTimeMicro creates a Carbon instance from a given date and time with microsecond. 从给定的年月日时分秒创建 Carbon 实例,包含微秒

func (Carbon) CreateFromDateTimeMilli added in v1.6.0

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

CreateFromDateTimeMilli creates a Carbon instance from a given date and time with millisecond. 从给定的年月日时分秒创建 Carbon 实例,包含毫秒

func (Carbon) CreateFromDateTimeNano added in v1.6.0

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

CreateFromDateTimeNano creates a Carbon instance from a given date and time with nanosecond. 从给定的年月日时分秒创建 Carbon 实例,包含纳秒

func (Carbon) CreateFromTime added in v1.1.1

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

CreateFromTime creates a Carbon instance from a given time. 从给定的时分秒创建 Carbon 实例

func (Carbon) CreateFromTimestamp added in v1.1.1

func (c Carbon) CreateFromTimestamp(timestamp int64, timezone ...string) Carbon

CreateFromTimestamp creates a Carbon instance from a given timestamp with second. 从给定的秒级时间戳创建 Carbon 实例

func (Carbon) CreateFromTimestampMicro added in v1.6.0

func (c Carbon) CreateFromTimestampMicro(timestamp int64, timezone ...string) Carbon

CreateFromTimestampMicro creates a Carbon instance from a given timestamp with microsecond. 从给定的微秒级时间戳创建 Carbon 实例

func (Carbon) CreateFromTimestampMilli added in v1.6.0

func (c Carbon) CreateFromTimestampMilli(timestamp int64, timezone ...string) Carbon

CreateFromTimestampMilli creates a Carbon instance from a given timestamp with millisecond. 从给定的微秒级时间戳创建 Carbon 实例

func (Carbon) CreateFromTimestampNano added in v1.6.0

func (c Carbon) CreateFromTimestampNano(timestamp int64, timezone ...string) Carbon

CreateFromTimestampNano creates a Carbon instance from a given timestamp with nanosecond. 从给定的纳秒级时间戳创建 Carbon 实例

func (Carbon) Date added in v1.6.0

func (c Carbon) Date() (year, month, day int)

Date gets current year, month, and day like 2020, 8, 5. 获取当前年月日

func (Carbon) DateMicro added in v1.6.5

func (c Carbon) DateMicro() (year, month, day, microsecond int)

DateMicro gets current year, month, day and microsecond like 2020, 8, 5, 999999. 获取当前年月日微秒

func (Carbon) DateMilli added in v1.6.5

func (c Carbon) DateMilli() (year, month, day, millisecond int)

DateMilli gets current year, month, day and millisecond like 2020, 8, 5, 999. 获取当前年月日毫秒

func (Carbon) DateNano added in v1.6.5

func (c Carbon) DateNano() (year, month, day, nanosecond int)

DateNano gets current year, month, day and nanosecond like 2020, 8, 5, 999999999. 获取当前年月日纳秒

func (Carbon) DateTime added in v1.6.0

func (c Carbon) DateTime() (year, month, day, hour, minute, second int)

DateTime gets current year, month, day, hour, minute, and second like 2020, 8, 5, 13, 14, 15. 获取当前年月日时分秒

func (Carbon) DateTimeMicro added in v1.6.0

func (c Carbon) DateTimeMicro() (year, month, day, hour, minute, second, microsecond int)

DateTimeMicro gets current year, month, day, hour, minute, second and microsecond like 2020, 8, 5, 13, 14, 15, 999999. 获取当前年月日时分秒微秒

func (Carbon) DateTimeMilli added in v1.6.0

func (c Carbon) DateTimeMilli() (year, month, day, hour, minute, second, millisecond int)

DateTimeMilli gets current year, month, day, hour, minute, second and millisecond like 2020, 8, 5, 13, 14, 15, 999. 获取当前年月日时分秒毫秒

func (Carbon) DateTimeNano added in v1.6.0

func (c Carbon) DateTimeNano() (year, month, day, hour, minute, second, nanosecond int)

DateTimeNano gets current year, month, day, hour, minute, second and nanosecond like 2020, 8, 5, 13, 14, 15, 999999999. 获取当前年月日时分秒纳秒

func (Carbon) Day added in v1.2.1

func (c Carbon) Day() int

Day gets current day like 5. 获取当前日

func (Carbon) DayOfMonth added in v1.2.0

func (c Carbon) DayOfMonth() int

DayOfMonth gets day of month like 30. 获取本月的第几天

func (Carbon) DayOfWeek added in v1.2.0

func (c Carbon) DayOfWeek() int

DayOfWeek gets day of week like 6. 获取本周的第几天

func (Carbon) DayOfYear added in v1.2.0

func (c Carbon) DayOfYear() int

DayOfYear gets day of year like 365. 获取本年的第几天

func (Carbon) DaysInMonth added in v1.2.0

func (c Carbon) DaysInMonth() int

DaysInMonth gets total days in month like 30. 获取本月的总天数

func (Carbon) DaysInYear added in v1.2.0

func (c Carbon) DaysInYear() int

DaysInYear gets total days in year like 365. 获取本年的总天数

func (Carbon) Decade added in v1.4.2

func (c Carbon) Decade() int

Decade gets current decade like 20. 获取当前年代

func (Carbon) DiffAbsInDays added in v1.2.2

func (c Carbon) DiffAbsInDays(carbon ...Carbon) int64

DiffAbsInDays gets the difference in days with absolute value. 相差多少天(绝对值)

func (Carbon) DiffAbsInHours added in v1.2.2

func (c Carbon) DiffAbsInHours(carbon ...Carbon) int64

DiffAbsInHours gets the difference in hours with absolute value. 相差多少小时(绝对值)

func (Carbon) DiffAbsInMinutes added in v1.2.2

func (c Carbon) DiffAbsInMinutes(carbon ...Carbon) int64

DiffAbsInMinutes gets the difference in minutes with absolute value. 相差多少分钟(绝对值)

func (Carbon) DiffAbsInMonths added in v1.6.2

func (c Carbon) DiffAbsInMonths(carbon ...Carbon) int64

DiffAbsInMonths gets the difference in months with absolute value. 相差多少月(绝对值)

func (Carbon) DiffAbsInSeconds added in v1.2.2

func (c Carbon) DiffAbsInSeconds(carbon ...Carbon) int64

DiffAbsInSeconds gets the difference in seconds with absolute value. 相差多少秒(绝对值)

func (Carbon) DiffAbsInString added in v1.6.2

func (c Carbon) DiffAbsInString(carbon ...Carbon) string

DiffAbsInString gets the difference in string with absolute value, i18n is supported. 相差字符串,支持i18n(绝对值)

func (Carbon) DiffAbsInWeeks added in v1.2.2

func (c Carbon) DiffAbsInWeeks(carbon ...Carbon) int64

DiffAbsInWeeks gets the difference in weeks with absolute value. 相差多少周(绝对值)

func (Carbon) DiffAbsInYears added in v1.6.2

func (c Carbon) DiffAbsInYears(carbon ...Carbon) int64

DiffAbsInYears gets the difference in years with absolute value. 相差多少年(绝对值)

func (Carbon) DiffForHumans added in v1.3.1

func (c Carbon) DiffForHumans(carbon ...Carbon) string

DiffForHumans gets the difference in a human-readable format, i18n is supported. 获取对人类友好的可读格式时间差,支持i18n

func (Carbon) DiffInDays added in v1.2.2

func (c Carbon) DiffInDays(carbon ...Carbon) int64

DiffInDays gets the difference in days. 相差多少天

func (Carbon) DiffInHours added in v1.2.2

func (c Carbon) DiffInHours(carbon ...Carbon) int64

DiffInHours gets the difference in hours. 相差多少小时

func (Carbon) DiffInMinutes added in v1.2.2

func (c Carbon) DiffInMinutes(carbon ...Carbon) int64

DiffInMinutes gets the difference in minutes. 相差多少分钟

func (Carbon) DiffInMonths added in v1.3.1

func (c Carbon) DiffInMonths(carbon ...Carbon) int64

DiffInMonths gets the difference in months. 相差多少月

func (Carbon) DiffInSeconds added in v1.2.2

func (c Carbon) DiffInSeconds(carbon ...Carbon) int64

DiffInSeconds gets the difference in seconds. 相差多少秒

func (Carbon) DiffInString added in v1.5.4

func (c Carbon) DiffInString(carbon ...Carbon) string

DiffInString gets the difference in string, i18n is supported. 相差字符串,支持i18n

func (Carbon) DiffInWeeks added in v1.2.2

func (c Carbon) DiffInWeeks(carbon ...Carbon) int64

DiffInWeeks gets the difference in weeks. 相差多少周

func (Carbon) DiffInYears added in v1.3.1

func (c Carbon) DiffInYears(carbon ...Carbon) int64

DiffInYears gets the difference in years. 相差多少年

func (Carbon) EndOfCentury added in v1.4.0

func (c Carbon) EndOfCentury() Carbon

EndOfCentury returns a Carbon instance for end of the century. 本世纪结束时间

func (Carbon) EndOfDay added in v1.1.1

func (c Carbon) EndOfDay() Carbon

EndOfDay returns a Carbon instance for end of the day. 本日结束时间

func (Carbon) EndOfDecade added in v1.4.2

func (c Carbon) EndOfDecade() Carbon

EndOfDecade returns a Carbon instance for end of the decade. 本年代结束时间

func (Carbon) EndOfHour added in v1.2.1

func (c Carbon) EndOfHour() Carbon

EndOfHour returns a Carbon instance for end of the hour. 小时结束时间

func (Carbon) EndOfMinute added in v1.2.1

func (c Carbon) EndOfMinute() Carbon

EndOfMinute returns a Carbon instance for end of the minute. 分钟结束时间

func (Carbon) EndOfMonth added in v1.1.1

func (c Carbon) EndOfMonth() Carbon

EndOfMonth returns a Carbon instance for end of the month. 本月结束时间

func (Carbon) EndOfQuarter added in v1.4.0

func (c Carbon) EndOfQuarter() Carbon

EndOfQuarter returns a Carbon instance for end of the quarter. 本季度结束时间

func (Carbon) EndOfSeason added in v1.4.2

func (c Carbon) EndOfSeason() Carbon

EndOfSeason returns a Carbon instance for end of the season. 本季节结束时间

func (Carbon) EndOfSecond added in v1.3.2

func (c Carbon) EndOfSecond() Carbon

EndOfSecond returns a Carbon instance for end of the second. 秒结束时间

func (Carbon) EndOfWeek added in v1.2.1

func (c Carbon) EndOfWeek() Carbon

EndOfWeek returns a Carbon instance for end of the week. 本周结束时间

func (Carbon) EndOfYear added in v1.1.1

func (c Carbon) EndOfYear() Carbon

EndOfYear returns a Carbon instance for end of the year. 本年结束时间

func (Carbon) Eq added in v1.2.4

func (c Carbon) Eq(t Carbon) bool

Eq reports whether equal. 是否等于

func (Carbon) Format added in v1.1.1

func (c Carbon) Format(format string, timezone ...string) string

Format outputs a string by format, it is shorthand for ToFormatString. 输出指定格式模板的时间字符串, 是 ToFormatString 的简写

func (Carbon) Gt added in v1.2.4

func (c Carbon) Gt(t Carbon) bool

Gt reports whether greater than. 是否大于

func (Carbon) Gte added in v1.2.4

func (c Carbon) Gte(t Carbon) bool

Gte reports whether greater than or equal. 是否大于等于

func (Carbon) Hour added in v1.2.1

func (c Carbon) Hour() int

Hour gets current hour like 13. 获取当前小时

func (Carbon) IsApril added in v1.1.1

func (c Carbon) IsApril() bool

IsApril reports whether is April. 是否是四月

func (Carbon) IsAquarius added in v1.3.4

func (c Carbon) IsAquarius() bool

IsAquarius reports whether is Aquarius. 是否是水瓶座

func (Carbon) IsAries added in v1.3.4

func (c Carbon) IsAries() bool

IsAries reports whether is Aries. 是否是白羊座

func (Carbon) IsAugust added in v1.1.1

func (c Carbon) IsAugust() bool

IsAugust reports whether is August. 是否是八月

func (Carbon) IsAutumn added in v1.4.2

func (c Carbon) IsAutumn() bool

IsAutumn reports whether is autumn. 是否是秋季

func (Carbon) IsCancer added in v1.3.4

func (c Carbon) IsCancer() bool

IsCancer reports whether is Cancer. 是否是巨蟹座

func (Carbon) IsCapricorn added in v1.3.4

func (c Carbon) IsCapricorn() bool

IsCapricorn reports whether is Capricorn. 是否是摩羯座

func (Carbon) IsDecember added in v1.1.1

func (c Carbon) IsDecember() bool

IsDecember reports whether is December. 是否是十二月

func (Carbon) IsFebruary added in v1.1.1

func (c Carbon) IsFebruary() bool

IsFebruary reports whether is February. 是否是二月

func (Carbon) IsFriday added in v1.1.1

func (c Carbon) IsFriday() bool

IsFriday reports whether is Friday. 是否是周五

func (Carbon) IsFuture added in v1.2.0

func (c Carbon) IsFuture() bool

IsFuture reports whether is future time. 是否是未来时间

func (Carbon) IsGemini added in v1.3.4

func (c Carbon) IsGemini() bool

IsGemini reports whether is Gemini. 是否是双子座

func (Carbon) IsInvalid added in v1.4.4

func (c Carbon) IsInvalid() bool

IsInvalid reports whether is invalid time. 是否是无效时间

func (Carbon) IsJanuary added in v1.1.1

func (c Carbon) IsJanuary() bool

IsJanuary reports whether is January. 是否是一月

func (Carbon) IsJuly added in v1.1.1

func (c Carbon) IsJuly() bool

IsJuly reports whether is July. 是否是七月

func (Carbon) IsJune added in v1.1.1

func (c Carbon) IsJune() bool

IsJune reports whether is June. 是否是六月

func (Carbon) IsLeapYear added in v1.1.1

func (c Carbon) IsLeapYear() bool

IsLeapYear reports whether is a leap year. 是否是闰年

func (Carbon) IsLeo added in v1.3.4

func (c Carbon) IsLeo() bool

IsLeo reports whether is Leo. 是否是狮子座

func (Carbon) IsLibra added in v1.3.4

func (c Carbon) IsLibra() bool

IsLibra reports whether is Libra. 是否是天秤座

func (Carbon) IsLongYear added in v1.2.2

func (c Carbon) IsLongYear() bool

IsLongYear reports whether is a long year, see https://en.wikipedia.org/wiki/ISO_8601#Week_dates. 是否是长年

func (Carbon) IsMarch added in v1.1.1

func (c Carbon) IsMarch() bool

IsMarch reports whether is March. 是否是三月

func (Carbon) IsMay added in v1.1.1

func (c Carbon) IsMay() bool

IsMay reports whether is May. 是否是五月

func (Carbon) IsMonday added in v1.1.1

func (c Carbon) IsMonday() bool

IsMonday reports whether is Monday. 是否是周一

func (Carbon) IsNovember added in v1.1.1

func (c Carbon) IsNovember() bool

IsNovember reports whether is November. 是否是十一月

func (Carbon) IsNow added in v1.2.1

func (c Carbon) IsNow() bool

IsNow reports whether is now time. 是否是当前时间

func (Carbon) IsOctober added in v1.1.1

func (c Carbon) IsOctober() bool

IsOctober reports whether is October. 是否是十月

func (Carbon) IsPast added in v1.2.0

func (c Carbon) IsPast() bool

IsPast reports whether is past time. 是否是过去时间

func (Carbon) IsPisces added in v1.3.4

func (c Carbon) IsPisces() bool

IsPisces reports whether is Pisces. 是否是双鱼座

func (Carbon) IsSagittarius added in v1.3.4

func (c Carbon) IsSagittarius() bool

IsSagittarius reports whether is Sagittarius. 是否是射手座

func (Carbon) IsSaturday added in v1.1.1

func (c Carbon) IsSaturday() bool

IsSaturday reports whether is Saturday. 是否是周六

func (Carbon) IsScorpio added in v1.3.4

func (c Carbon) IsScorpio() bool

IsScorpio reports whether is Scorpio. 是否是天蝎座

func (Carbon) IsSeptember added in v1.1.1

func (c Carbon) IsSeptember() bool

IsSeptember reports whether is September. 是否是九月

func (Carbon) IsSpring added in v1.4.2

func (c Carbon) IsSpring() bool

IsSpring reports whether is spring. 是否是春季

func (Carbon) IsSummer added in v1.4.2

func (c Carbon) IsSummer() bool

IsSummer reports whether is summer. 是否是夏季

func (Carbon) IsSunday added in v1.1.1

func (c Carbon) IsSunday() bool

IsSunday reports whether is Sunday. 是否是周日

func (Carbon) IsTaurus added in v1.3.4

func (c Carbon) IsTaurus() bool

IsTaurus reports whether is Taurus. 是否是金牛座

func (Carbon) IsThursday added in v1.1.1

func (c Carbon) IsThursday() bool

IsThursday reports whether is Thursday. 是否是周四

func (Carbon) IsToday added in v1.1.1

func (c Carbon) IsToday() bool

IsToday reports whether is today. 是否是今天

func (Carbon) IsTomorrow added in v1.1.1

func (c Carbon) IsTomorrow() bool

IsTomorrow reports whether is tomorrow. 是否是明天

func (Carbon) IsTuesday added in v1.1.1

func (c Carbon) IsTuesday() bool

IsTuesday reports whether is Tuesday. 是否是周二

func (Carbon) IsValid added in v1.6.3

func (c Carbon) IsValid() bool

IsValid reports whether is valid time. 是否是有效时间

func (Carbon) IsVirgo added in v1.3.4

func (c Carbon) IsVirgo() bool

IsVirgo reports whether is Virgo. 是否是处女座

func (Carbon) IsWednesday added in v1.1.1

func (c Carbon) IsWednesday() bool

IsWednesday reports whether is Wednesday. 是否是周三

func (Carbon) IsWeekday added in v1.2.0

func (c Carbon) IsWeekday() bool

IsWeekday reports whether is weekday. 是否是工作日

func (Carbon) IsWeekend added in v1.2.0

func (c Carbon) IsWeekend() bool

IsWeekend reports whether is weekend. 是否是周末

func (Carbon) IsWinter added in v1.4.2

func (c Carbon) IsWinter() bool

IsWinter reports whether is winter. 是否是冬季

func (Carbon) IsYesterday added in v1.1.1

func (c Carbon) IsYesterday() bool

IsYesterday reports whether is yesterday. 是否是昨天

func (Carbon) IsZero added in v1.2.0

func (c Carbon) IsZero() bool

IsZero reports whether is zero time. 是否是零值时间

func (Carbon) Layout added in v1.4.4

func (c Carbon) Layout(layout string, timezone ...string) string

Layout outputs a string by layout, it is shorthand for ToLayoutString. 输出指定布局模板的时间字符串, 是 ToLayoutString 的简写

func (Carbon) Locale added in v1.3.1

func (c Carbon) Locale() string

Locale gets locale name like "zh-CN". 获取语言区域

func (Carbon) Location added in v1.4.4

func (c Carbon) Location() string

Location gets location name like "PRC". 获取位置

func (Carbon) Lt added in v1.2.4

func (c Carbon) Lt(t Carbon) bool

Lt reports whether less than. 是否小于

func (Carbon) Lte added in v1.2.4

func (c Carbon) Lte(t Carbon) bool

Lte reports whether less than or equal. 是否小于等于

func (Carbon) Lunar added in v1.4.1

func (c Carbon) Lunar() (l lunar)

Lunar converts the gregorian calendar to the lunar calendar. 将公历转为农历

func (Carbon) Microsecond added in v1.2.3

func (c Carbon) Microsecond() int

Microsecond gets current microsecond like 999999. 获取当前微秒数,6位数字

func (Carbon) Millisecond added in v1.2.3

func (c Carbon) Millisecond() int

Millisecond gets current millisecond like 999. 获取当前毫秒数,3位数字

func (Carbon) Minute added in v1.2.1

func (c Carbon) Minute() int

Minute gets current minute like 14. 获取当前分钟数

func (Carbon) Month added in v1.2.1

func (c Carbon) Month() int

Month gets current month like 8. 获取当前月

func (Carbon) MonthOfYear added in v1.2.0

func (c Carbon) MonthOfYear() int

MonthOfYear gets month of year like 12. 获取本年的第几月

func (Carbon) Nanosecond added in v1.2.3

func (c Carbon) Nanosecond() int

Nanosecond gets current nanosecond like 999999999. 获取当前纳秒数,9位数字

func (Carbon) Ne added in v1.2.4

func (c Carbon) Ne(t Carbon) bool

Ne reports whether not equal. 是否不等于

func (Carbon) Now added in v1.1.1

func (c Carbon) Now(timezone ...string) Carbon

Now returns a Carbon instance for now. 当前

func (Carbon) Offset added in v1.4.4

func (c Carbon) Offset() int

Offset gets offset seconds from the UTC timezone like 28800. 获取距离UTC时区的偏移量,单位秒

func (Carbon) Parse added in v1.1.1

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

Parse parses a standard string as a Carbon instance. 将标准格式时间字符串解析成 Carbon 实例

func (Carbon) ParseByFormat added in v1.1.2

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

ParseByFormat parses a string as a Carbon instance by format. 通过格式模板将字符串解析成 carbon 实例

func (Carbon) ParseByLayout added in v1.3.0

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

ParseByLayout parses a string as a Carbon instance by layout. 通过布局模板将字符串解析成 carbon 实例

func (Carbon) Quarter added in v1.2.3

func (c Carbon) Quarter() (quarter int)

Quarter gets current quarter like 3. 获取当前季度

func (*Carbon) Scan added in v1.1.1

func (c *Carbon) Scan(v interface{}) error

Scan an interface used by Scan in package database/sql for Scanning value from database to local golang variable.

func (Carbon) Season added in v1.4.2

func (c Carbon) Season() string

Season gets season name according to the meteorological division method like "Spring", i18n is supported. 获取当前季节(以气象划分),支持i18n

func (Carbon) Second added in v1.2.1

func (c Carbon) Second() int

Second gets current second like 15. 获取当前秒数

func (Carbon) SetDate added in v1.6.0

func (c Carbon) SetDate(year, month, day int) Carbon

SetDate sets year, month and day. 设置年月日

func (Carbon) SetDateTime added in v1.6.0

func (c Carbon) SetDateTime(year, month, day, hour, minute, second int) Carbon

SetDateTime sets year, month, day, hour, minute and second. 设置年月日时分秒

func (Carbon) SetDateTimeMicro added in v1.6.2

func (c Carbon) SetDateTimeMicro(year, month, day, hour, minute, second, microsecond int) Carbon

SetDateTimeMicro sets year, month, day, hour, minute, second and microsecond. 设置年月日时分秒微秒

func (Carbon) SetDateTimeMilli added in v1.6.2

func (c Carbon) SetDateTimeMilli(year, month, day, hour, minute, second, millisecond int) Carbon

SetDateTimeMilli sets year, month, day, hour, minute, second and millisecond. 设置年月日时分秒毫秒

func (Carbon) SetDateTimeNano added in v1.6.2

func (c Carbon) SetDateTimeNano(year, month, day, hour, minute, second, nanosecond int) Carbon

SetDateTimeNano sets year, month, day, hour, minute, second and nanosecond. 设置年月日时分秒纳秒

func (Carbon) SetDay added in v1.2.2

func (c Carbon) SetDay(day int) Carbon

SetDay sets day. 设置日期

func (Carbon) SetHour added in v1.2.2

func (c Carbon) SetHour(hour int) Carbon

SetHour sets hour. 设置小时

func (Carbon) SetLanguage added in v1.3.2

func (c Carbon) SetLanguage(lang *Language) Carbon

SetLanguage sets language. 设置语言对象

func (Carbon) SetLocale added in v1.3.1

func (c Carbon) SetLocale(locale string) Carbon

SetLocale sets locale. 设置语言区域

func (Carbon) SetMicrosecond added in v1.3.6

func (c Carbon) SetMicrosecond(microsecond int) Carbon

SetMicrosecond sets microsecond. 设置微秒

func (Carbon) SetMillisecond added in v1.3.6

func (c Carbon) SetMillisecond(millisecond int) Carbon

SetMillisecond sets millisecond. 设置毫秒

func (Carbon) SetMinute added in v1.2.2

func (c Carbon) SetMinute(minute int) Carbon

SetMinute sets minute. 设置分钟

func (Carbon) SetMonth added in v1.2.2

func (c Carbon) SetMonth(month int) Carbon

SetMonth sets month. 设置月份

func (Carbon) SetMonthNoOverflow added in v1.5.2

func (c Carbon) SetMonthNoOverflow(month int) Carbon

SetMonthNoOverflow sets month without overflowing month. 设置月份(月份不溢出)

func (Carbon) SetNanosecond added in v1.3.6

func (c Carbon) SetNanosecond(nanosecond int) Carbon

SetNanosecond sets nanosecond. 设置纳秒

func (Carbon) SetSecond added in v1.2.2

func (c Carbon) SetSecond(second int) Carbon

SetSecond sets second. 设置秒数

func (Carbon) SetTime added in v1.6.0

func (c Carbon) SetTime(hour, minute, second int) Carbon

SetTime sets hour, minute and second. 设置时分秒

func (Carbon) SetTimezone added in v1.2.2

func (c Carbon) SetTimezone(name string) Carbon

SetTimezone sets timezone. 设置时区

func (Carbon) SetWeekStartsAt added in v1.5.2

func (c Carbon) SetWeekStartsAt(day string) Carbon

SetWeekStartsAt sets start day of the week. 设置一周的开始日期

func (Carbon) SetYear added in v1.2.2

func (c Carbon) SetYear(year int) Carbon

SetYear sets year. 设置年份

func (Carbon) SetYearNoOverflow added in v1.5.2

func (c Carbon) SetYearNoOverflow(year int) Carbon

SetYearNoOverflow sets year without overflowing month. 设置年份(月份不溢出)

func (Carbon) StartOfCentury added in v1.4.0

func (c Carbon) StartOfCentury() Carbon

StartOfCentury returns a Carbon instance for start of the century. 本世纪开始时间

func (Carbon) StartOfDay added in v1.1.1

func (c Carbon) StartOfDay() Carbon

StartOfDay returns a Carbon instance for start of the day. 本日开始时间

func (Carbon) StartOfDecade added in v1.4.2

func (c Carbon) StartOfDecade() Carbon

StartOfDecade returns a Carbon instance for start of the decade. 本年代开始时间

func (Carbon) StartOfHour added in v1.2.2

func (c Carbon) StartOfHour() Carbon

StartOfHour returns a Carbon instance for start of the hour. 小时开始时间

func (Carbon) StartOfMinute added in v1.2.2

func (c Carbon) StartOfMinute() Carbon

StartOfMinute returns a Carbon instance for start of the minute. 分钟开始时间

func (Carbon) StartOfMonth added in v1.1.1

func (c Carbon) StartOfMonth() Carbon

StartOfMonth returns a Carbon instance for start of the month. 本月开始时间

func (Carbon) StartOfQuarter added in v1.4.0

func (c Carbon) StartOfQuarter() Carbon

StartOfQuarter returns a Carbon instance for start of the quarter. 本季度开始时间

func (Carbon) StartOfSeason added in v1.4.2

func (c Carbon) StartOfSeason() Carbon

StartOfSeason returns a Carbon instance for start of the season. 本季节开始时间

func (Carbon) StartOfSecond added in v1.3.2

func (c Carbon) StartOfSecond() Carbon

StartOfSecond returns a Carbon instance for start of the second. 秒开始时间

func (Carbon) StartOfWeek added in v1.2.2

func (c Carbon) StartOfWeek() Carbon

StartOfWeek returns a Carbon instance for start of the week. 本周开始时间

func (Carbon) StartOfYear added in v1.1.1

func (c Carbon) StartOfYear() Carbon

StartOfYear returns a Carbon instance for start of the year. 本年开始时间

func (Carbon) String added in v1.3.7

func (c Carbon) String() string

String outputs a string in date and time format, implement Stringer interface. 实现 Stringer 接口

func (Carbon) SubCenturies added in v1.2.6

func (c Carbon) SubCenturies(centuries int) Carbon

SubCenturies subtracts some centuries. N个世纪前

func (Carbon) SubCenturiesNoOverflow added in v1.3.0

func (c Carbon) SubCenturiesNoOverflow(centuries int) Carbon

SubCenturiesNoOverflow subtracts some centuries without overflowing month. N个世纪前(月份不溢出)

func (Carbon) SubCentury added in v1.2.6

func (c Carbon) SubCentury() Carbon

SubCentury subtracts one century. 1个世纪前

func (Carbon) SubCenturyNoOverflow added in v1.3.0

func (c Carbon) SubCenturyNoOverflow() Carbon

SubCenturyNoOverflow subtracts one century without overflowing month. 1个世纪前(月份不溢出)

func (Carbon) SubDay added in v1.1.1

func (c Carbon) SubDay() Carbon

SubDay subtracts one day. 1天前

func (Carbon) SubDays added in v1.1.1

func (c Carbon) SubDays(days int) Carbon

SubDays subtracts some days. N天前

func (Carbon) SubDecade added in v1.5.2

func (c Carbon) SubDecade() Carbon

SubDecade subtracts one decade. 1个年代后

func (Carbon) SubDecadeNoOverflow added in v1.5.2

func (c Carbon) SubDecadeNoOverflow() Carbon

SubDecadeNoOverflow subtracts one decade without overflowing month. 1个年代后(月份不溢出)

func (Carbon) SubDecades added in v1.5.2

func (c Carbon) SubDecades(decades int) Carbon

SubDecades subtracts some decades. N个年代后

func (Carbon) SubDecadesNoOverflow added in v1.5.2

func (c Carbon) SubDecadesNoOverflow(decades int) Carbon

SubDecadesNoOverflow subtracts some decades without overflowing month. N个年代后(月份不溢出)

func (Carbon) SubDuration added in v1.2.4

func (c Carbon) SubDuration(duration string) Carbon

SubDuration subtracts one duration. 按照持续时长字符串减少时间,支持整数/浮点数和符号ns(纳秒)、us(微妙)、ms(毫秒)、s(秒)、m(分钟)、h(小时)的组合

func (Carbon) SubHour added in v1.1.1

func (c Carbon) SubHour() Carbon

SubHour subtracts one hour. 1小时前

func (Carbon) SubHours added in v1.1.1

func (c Carbon) SubHours(hours int) Carbon

SubHours subtracts some hours. N小时前

func (Carbon) SubMicrosecond added in v1.6.5

func (c Carbon) SubMicrosecond() Carbon

SubMicrosecond subtracts one microsecond. 1微秒前

func (Carbon) SubMicroseconds added in v1.6.5

func (c Carbon) SubMicroseconds(microseconds int) Carbon

SubMicroseconds subtracts some microseconds. N微秒前

func (Carbon) SubMillisecond added in v1.6.5

func (c Carbon) SubMillisecond() Carbon

SubMillisecond subtracts one millisecond. 1毫秒前

func (Carbon) SubMilliseconds added in v1.6.5

func (c Carbon) SubMilliseconds(milliseconds int) Carbon

SubMilliseconds subtracts some milliseconds. N毫秒前

func (Carbon) SubMinute added in v1.1.1

func (c Carbon) SubMinute() Carbon

SubMinute subtracts one minute. 1分钟前

func (Carbon) SubMinutes added in v1.1.1

func (c Carbon) SubMinutes(minutes int) Carbon

SubMinutes subtracts some minutes. N分钟前

func (Carbon) SubMonth added in v1.1.1

func (c Carbon) SubMonth() Carbon

SubMonth subtracts one month. 1个月前

func (Carbon) SubMonthNoOverflow added in v1.3.0

func (c Carbon) SubMonthNoOverflow() Carbon

SubMonthNoOverflow subtracts one month without overflowing month. 1个月前(月份不溢出)

func (Carbon) SubMonths added in v1.1.1

func (c Carbon) SubMonths(months int) Carbon

SubMonths subtracts some months. N个月前

func (Carbon) SubMonthsNoOverflow added in v1.3.0

func (c Carbon) SubMonthsNoOverflow(months int) Carbon

SubMonthsNoOverflow subtracts some months without overflowing month. N个月前(月份不溢出)

func (Carbon) SubNanosecond added in v1.6.5

func (c Carbon) SubNanosecond() Carbon

SubNanosecond subtracts one nanosecond. 1纳秒前

func (Carbon) SubNanoseconds added in v1.6.5

func (c Carbon) SubNanoseconds(nanosecond int) Carbon

SubNanoseconds subtracts some nanosecond. N纳秒前

func (Carbon) SubQuarter added in v1.2.3

func (c Carbon) SubQuarter() Carbon

SubQuarter subtracts one quarter. 1个季度前

func (Carbon) SubQuarterNoOverflow added in v1.3.0

func (c Carbon) SubQuarterNoOverflow() Carbon

SubQuarterNoOverflow subtracts one quarter without overflowing month. 1个季度前(月份不溢出)

func (Carbon) SubQuarters added in v1.2.3

func (c Carbon) SubQuarters(quarters int) Carbon

SubQuarters subtracts some quarters. N个季度前

func (Carbon) SubQuartersNoOverflow added in v1.3.0

func (c Carbon) SubQuartersNoOverflow(quarters int) Carbon

SubQuartersNoOverflow subtracts some quarters without overflowing month. N个季度前(月份不溢出)

func (Carbon) SubSecond added in v1.1.1

func (c Carbon) SubSecond() Carbon

SubSecond subtracts one second. 1秒钟前

func (Carbon) SubSeconds added in v1.1.1

func (c Carbon) SubSeconds(seconds int) Carbon

SubSeconds subtracts some seconds. N秒钟前

func (Carbon) SubWeek added in v1.1.1

func (c Carbon) SubWeek() Carbon

SubWeek subtracts one week. 1周前

func (Carbon) SubWeeks added in v1.1.1

func (c Carbon) SubWeeks(weeks int) Carbon

SubWeeks subtracts some weeks. N周前

func (Carbon) SubYear added in v1.1.1

func (c Carbon) SubYear() Carbon

SubYear subtracts one year. 1年前

func (Carbon) SubYearNoOverflow added in v1.3.0

func (c Carbon) SubYearNoOverflow() Carbon

SubYearNoOverflow subtracts one year without overflowing month. 1年前(月份不溢出)

func (Carbon) SubYears added in v1.1.1

func (c Carbon) SubYears(years int) Carbon

SubYears subtracts some years. N年前

func (Carbon) SubYearsNoOverflow added in v1.3.0

func (c Carbon) SubYearsNoOverflow(years int) Carbon

SubYearsNoOverflow subtracts some years without overflowing month. N年前(月份不溢出)

func (Carbon) Time added in v1.1.1

func (c Carbon) Time() (hour, minute, second int)

Time gets current hour, minute, and second like 13, 14, 15. 获取当前时分秒

func (Carbon) TimeMicro added in v1.6.5

func (c Carbon) TimeMicro() (hour, minute, second, microsecond int)

TimeMicro gets current hour, minute, second and microsecond like 13, 14, 15, 999999. 获取当前时分秒微秒

func (Carbon) TimeMilli added in v1.6.5

func (c Carbon) TimeMilli() (hour, minute, second, millisecond int)

TimeMilli gets current hour, minute, second and millisecond like 13, 14, 15, 999. 获取当前时分秒毫秒

func (Carbon) TimeNano added in v1.6.5

func (c Carbon) TimeNano() (hour, minute, second, nanosecond int)

TimeNano gets current hour, minute, second and nanosecond like 13, 14, 15, 999999999. 获取当前时分秒纳秒

func (Carbon) Timestamp added in v1.5.2

func (c Carbon) Timestamp() int64

Timestamp gets timestamp with second like 1596604455, it is shorthand for TimestampWithSecond. 获取秒级时间戳, 是 TimestampWithSecond 的简写

func (Carbon) TimestampMicro added in v1.6.0

func (c Carbon) TimestampMicro() int64

TimestampMicro gets timestamp with microsecond like 1596604455000000, it is shorthand for TimestampWithMicrosecond. 获取微秒级时间戳, 是 TimestampWithMicrosecond 的简写

func (Carbon) TimestampMilli added in v1.6.0

func (c Carbon) TimestampMilli() int64

TimestampMilli gets timestamp with millisecond like 1596604455000, it is shorthand for TimestampWithMillisecond. 获取毫秒级时间戳, 是 TimestampMilli 的简写

func (Carbon) TimestampNano added in v1.6.0

func (c Carbon) TimestampNano() int64

TimestampNano gets timestamp with nanosecond like 1596604455000000000, it is shorthand for TimestampWithNanosecond. 获取纳秒级时间戳, 是 TimestampWithNanosecond 的简写

func (Carbon) TimestampWithMicrosecond added in v1.5.2

func (c Carbon) TimestampWithMicrosecond() int64

TimestampWithMicrosecond gets timestamp with microsecond like 1596604455000000, it will be replaced by TimestampMicro. 获取微秒级时间戳

func (Carbon) TimestampWithMillisecond added in v1.5.2

func (c Carbon) TimestampWithMillisecond() int64

TimestampWithMillisecond gets timestamp with millisecond like 1596604455000, it will be replaced by TimestampMilli. 获取毫秒级时间戳

func (Carbon) TimestampWithNanosecond added in v1.5.2

func (c Carbon) TimestampWithNanosecond() int64

TimestampWithNanosecond gets timestamp with nanosecond like 1596604455000000000, it will be replaced by TimestampNano. 获取纳秒级时间戳

func (Carbon) TimestampWithSecond added in v1.5.2

func (c Carbon) TimestampWithSecond() int64

TimestampWithSecond gets timestamp with second like 1596604455, it will be replaced by Timestamp. 输出秒级时间戳

func (Carbon) Timezone added in v1.1.1

func (c Carbon) Timezone() string

Timezone gets timezone name like "CST". 获取时区

func (Carbon) ToANSICString added in v1.6.1

func (c Carbon) ToANSICString(timezone ...string) string

ToANSICString outputs a string in "Mon Jan _2 15:04:05 2006" layout. 输出 "Mon Jan _2 15:04:05 2006" 格式字符串

func (Carbon) ToAtomString added in v1.2.0

func (c Carbon) ToAtomString(timezone ...string) string

ToAtomString outputs a string in "2006-01-02T15:04:05Z07:00" layout. 输出 "2006-01-02T15:04:05Z07:00" 格式字符串

func (Carbon) ToCookieString added in v1.2.0

func (c Carbon) ToCookieString(timezone ...string) string

ToCookieString outputs a string in "Monday, 02-Jan-2006 15:04:05 MST" layout. 输出 "Monday, 02-Jan-2006 15:04:05 MST" 格式字符串

func (Carbon) ToDateMicroString added in v1.6.5

func (c Carbon) ToDateMicroString(timezone ...string) string

ToDateMicroString outputs a string in "2006-01-02.999999" layout. 输出 "2006-01-02.999999" 格式字符串

func (Carbon) ToDateMilliString added in v1.6.5

func (c Carbon) ToDateMilliString(timezone ...string) string

ToDateMilliString outputs a string in "2006-01-02.999" layout. 输出 "2006-01-02.999" 格式字符串

func (Carbon) ToDateNanoString added in v1.6.5

func (c Carbon) ToDateNanoString(timezone ...string) string

ToDateNanoString outputs a string in "2006-01-02.999999999" layout. 输出 "2006-01-02.999999999" 格式字符串

func (Carbon) ToDateString added in v1.1.1

func (c Carbon) ToDateString(timezone ...string) string

ToDateString outputs a string in "2006-01-02" layout. 输出 "2006-01-02" 格式字符串

func (Carbon) ToDateTimeMicroString added in v1.6.0

func (c Carbon) ToDateTimeMicroString(timezone ...string) string

ToDateTimeMicroString outputs a string in "2006-01-02 15:04:05.999999" layout. 输出 "2006-01-02 15:04:05.999999" 格式字符串

func (Carbon) ToDateTimeMilliString added in v1.6.0

func (c Carbon) ToDateTimeMilliString(timezone ...string) string

ToDateTimeMilliString outputs a string in "2006-01-02 15:04:05.999" layout. 输出 "2006-01-02 15:04:05.999" 格式字符串

func (Carbon) ToDateTimeNanoString added in v1.6.0

func (c Carbon) ToDateTimeNanoString(timezone ...string) string

ToDateTimeNanoString outputs a string in "2006-01-02 15:04:05.999999999" layout. 输出 "2006-01-02 15:04:05.999999999" 格式字符串

func (Carbon) ToDateTimeString added in v1.1.1

func (c Carbon) ToDateTimeString(timezone ...string) string

ToDateTimeString outputs a string in "2006-01-02 15:04:05" layout. 输出 "2006-01-02 15:04:05" 格式字符串

func (Carbon) ToDayDateTimeString added in v1.2.0

func (c Carbon) ToDayDateTimeString(timezone ...string) string

ToDayDateTimeString outputs a string in "Mon, Jan 2, 2006 3:04 PM" layout. 输出 "Mon, Jan 2, 2006 3:04 PM" 格式字符串

func (Carbon) ToFormatString added in v1.2.0

func (c Carbon) ToFormatString(format string, timezone ...string) string

ToFormatString outputs a string by format. 输出指定格式模板的时间字符串

func (Carbon) ToIso8601MicroString added in v1.6.1

func (c Carbon) ToIso8601MicroString(timezone ...string) string

ToIso8601MicroString outputs a string in "2006-01-02T15:04:05.999999-07:00" layout. 输出 "2006-01-02T15:04:05.999999-07:00" 格式字符串

func (Carbon) ToIso8601MilliString added in v1.6.1

func (c Carbon) ToIso8601MilliString(timezone ...string) string

ToIso8601MilliString outputs a string in "2006-01-02T15:04:05.999-07:00" layout. 输出 "2006-01-02T15:04:05.999-07:00" 格式字符串

func (Carbon) ToIso8601NanoString added in v1.6.1

func (c Carbon) ToIso8601NanoString(timezone ...string) string

ToIso8601NanoString outputs a string in "2006-01-02T15:04:05.999999999-07:00" layout. 输出 "2006-01-02T15:04:05.999999999-07:00" 格式字符串

func (Carbon) ToIso8601String added in v1.4.4

func (c Carbon) ToIso8601String(timezone ...string) string

ToIso8601String outputs a string in "2006-01-02T15:04:05-07:00" layout. 输出 "2006-01-02T15:04:05-07:00" 格式字符串

func (Carbon) ToKitchenString added in v1.2.0

func (c Carbon) ToKitchenString(timezone ...string) string

ToKitchenString outputs a string in "3:04PM" layout. 输出 "3:04PM" 格式字符串

func (Carbon) ToLayoutString added in v1.4.4

func (c Carbon) ToLayoutString(layout string, timezone ...string) string

ToLayoutString outputs a string by layout. 输出指定布局模板的时间字符串

func (Carbon) ToMonthString added in v1.3.4

func (c Carbon) ToMonthString(timezone ...string) string

ToMonthString outputs a string in month layout like "January", i18n is supported. 输出完整月份字符串,支持i18n

func (Carbon) ToRfc1036String added in v1.3.0

func (c Carbon) ToRfc1036String(timezone ...string) string

ToRfc1036String outputs a string in "Mon, 02 Jan 06 15:04:05 -0700" layout. 输出 "Mon, 02 Jan 06 15:04:05 -0700" 格式字符串

func (Carbon) ToRfc1123String added in v1.3.0

func (c Carbon) ToRfc1123String(timezone ...string) string

ToRfc1123String outputs a string in "Mon, 02 Jan 2006 15:04:05 MST" layout. 输出 "Mon, 02 Jan 2006 15:04:05 MST" 格式字符串

func (Carbon) ToRfc1123zString added in v1.4.5

func (c Carbon) ToRfc1123zString(timezone ...string) string

ToRfc1123zString outputs a string in "Mon, 02 Jan 2006 15:04:05 -0700" layout. 输出 "Mon, 02 Jan 2006 15:04:05 -0700" 格式字符串

func (Carbon) ToRfc2822String added in v1.3.0

func (c Carbon) ToRfc2822String(timezone ...string) string

ToRfc2822String outputs a string in "Mon, 02 Jan 2006 15:04:05 -0700" layout. 输出 "Mon, 02 Jan 2006 15:04:05 -0700" 格式字符串

func (Carbon) ToRfc3339MicroString added in v1.6.0

func (c Carbon) ToRfc3339MicroString(timezone ...string) string

ToRfc3339MicroString outputs a string in "2006-01-02T15:04:05.999999Z07:00" layout. 输出 "2006-01-02T15:04:05.999999Z07:00" 格式字符串

func (Carbon) ToRfc3339MilliString added in v1.6.0

func (c Carbon) ToRfc3339MilliString(timezone ...string) string

ToRfc3339MilliString outputs a string in "2006-01-02T15:04:05.999Z07:00" layout. 输出 "2006-01-02T15:04:05.999Z07:00" 格式字符串

func (Carbon) ToRfc3339NanoString added in v1.6.0

func (c Carbon) ToRfc3339NanoString(timezone ...string) string

ToRfc3339NanoString outputs a string in "2006-01-02T15:04:05.999999999Z07:00" layout. 输出 "2006-01-02T15:04:05.999999999Z07:00" 格式字符串

func (Carbon) ToRfc3339String added in v1.3.0

func (c Carbon) ToRfc3339String(timezone ...string) string

ToRfc3339String outputs a string in "2006-01-02T15:04:05Z07:00" layout. 输出 "2006-01-02T15:04:05Z07:00" 格式字符串

func (Carbon) ToRfc7231String added in v1.3.0

func (c Carbon) ToRfc7231String(timezone ...string) string

ToRfc7231String outputs a string in "Mon, 02 Jan 2006 15:04:05 GMT" layout. 输出 "Mon, 02 Jan 2006 15:04:05 GMT" 格式字符串

func (Carbon) ToRfc822String added in v1.3.0

func (c Carbon) ToRfc822String(timezone ...string) string

ToRfc822String outputs a string in "02 Jan 06 15:04 MST" layout. 输出 "02 Jan 06 15:04 MST" 格式字符串

func (Carbon) ToRfc822zString added in v1.3.0

func (c Carbon) ToRfc822zString(timezone ...string) string

ToRfc822zString outputs a string in "02 Jan 06 15:04 -0700" layout. 输出 "02 Jan 06 15:04 -0700" 格式字符串

func (Carbon) ToRfc850String added in v1.3.0

func (c Carbon) ToRfc850String(timezone ...string) string

ToRfc850String outputs a string in "Monday, 02-Jan-06 15:04:05 MST" layout. 输出 "Monday, 02-Jan-06 15:04:05 MST" 格式字符串

func (Carbon) ToRssString added in v1.2.0

func (c Carbon) ToRssString(timezone ...string) string

ToRssString outputs a string in "Mon, 02 Jan 2006 15:04:05 -0700" format. 输出 "Mon, 02 Jan 2006 15:04:05 -0700" 格式字符串

func (Carbon) ToRubyDateString added in v1.2.0

func (c Carbon) ToRubyDateString(timezone ...string) string

ToRubyDateString outputs a string in "Mon Jan 02 15:04:05 -0700 2006" layout. 输出 "Mon Jan 02 15:04:05 -0700 2006" 格式字符串

func (Carbon) ToShortDateMicroString added in v1.6.5

func (c Carbon) ToShortDateMicroString(timezone ...string) string

ToShortDateMicroString outputs a string in "20060102.999999" layout. 输出 "20060102.999999" 格式字符串

func (Carbon) ToShortDateMilliString added in v1.6.5

func (c Carbon) ToShortDateMilliString(timezone ...string) string

ToShortDateMilliString outputs a string in "20060102.999" layout. 输出 "20060102.999" 格式字符串

func (Carbon) ToShortDateNanoString added in v1.6.5

func (c Carbon) ToShortDateNanoString(timezone ...string) string

ToShortDateNanoString outputs a string in "20060102.999999999" layout. 输出 "20060102.999999999" 格式字符串

func (Carbon) ToShortDateString added in v1.4.4

func (c Carbon) ToShortDateString(timezone ...string) string

ToShortDateString outputs a string in "20060102" layout. 输出 "20060102" 格式字符串

func (Carbon) ToShortDateTimeMicroString added in v1.6.0

func (c Carbon) ToShortDateTimeMicroString(timezone ...string) string

ToShortDateTimeMicroString outputs a string in "20060102150405.999999" layout. 输出 "20060102150405.999999" 格式字符串

func (Carbon) ToShortDateTimeMilliString added in v1.6.0

func (c Carbon) ToShortDateTimeMilliString(timezone ...string) string

ToShortDateTimeMilliString outputs a string in "20060102150405.999" layout. 输出 "20060102150405.999" 格式字符串

func (Carbon) ToShortDateTimeNanoString added in v1.6.0

func (c Carbon) ToShortDateTimeNanoString(timezone ...string) string

ToShortDateTimeNanoString outputs a string in "20060102150405.999999999" layout. 输出 "20060102150405.999999999" 格式字符串

func (Carbon) ToShortDateTimeString added in v1.4.4

func (c Carbon) ToShortDateTimeString(timezone ...string) string

ToShortDateTimeString outputs a string in "20060102150405" layout. 输出 "20060102150405" 格式字符串

func (Carbon) ToShortMonthString added in v1.3.4

func (c Carbon) ToShortMonthString(timezone ...string) string

ToShortMonthString outputs a string in short month layout like "Jan", i18n is supported. 输出缩写月份字符串,支持i18n

func (Carbon) ToShortTimeMicroString added in v1.6.5

func (c Carbon) ToShortTimeMicroString(timezone ...string) string

ToShortTimeMicroString outputs a string in "150405.999999" layout. 输出 "150405.999999" 格式字符串

func (Carbon) ToShortTimeMilliString added in v1.6.5

func (c Carbon) ToShortTimeMilliString(timezone ...string) string

ToShortTimeMilliString outputs a string in "150405.999" layout. 输出 "150405.999" 格式字符串

func (Carbon) ToShortTimeNanoString added in v1.6.5

func (c Carbon) ToShortTimeNanoString(timezone ...string) string

ToShortTimeNanoString outputs a string in "150405.999999999" layout. 输出 "150405.999999999" 格式字符串

func (Carbon) ToShortTimeString added in v1.4.4

func (c Carbon) ToShortTimeString(timezone ...string) string

ToShortTimeString outputs a string in "150405" layout. 输出 "150405" 格式字符串

func (Carbon) ToShortWeekString added in v1.3.4

func (c Carbon) ToShortWeekString(timezone ...string) string

ToShortWeekString outputs a string in short week layout like "Sun", i18n is supported. 输出缩写星期字符串,支持i18n

func (Carbon) ToString added in v1.2.0

func (c Carbon) ToString(timezone ...string) string

ToString outputs a string in "2006-01-02 15:04:05.999999999 -0700 MST" layout. 输出 "2006-01-02 15:04:05.999999999 -0700 MST" 格式字符串

func (Carbon) ToTimeMicroString added in v1.6.5

func (c Carbon) ToTimeMicroString(timezone ...string) string

ToTimeMicroString outputs a string in "15:04:05.999999" layout. 输出 "15:04:05.999999" 格式字符串

func (Carbon) ToTimeMilliString added in v1.6.5

func (c Carbon) ToTimeMilliString(timezone ...string) string

ToTimeMilliString outputs a string in "15:04:05.999" layout. 输出 "15:04:05.999" 格式字符串

func (Carbon) ToTimeNanoString added in v1.6.5

func (c Carbon) ToTimeNanoString(timezone ...string) string

ToTimeNanoString outputs a string in "15:04:05.999999999" layout. 输出 "15:04:05.999999999" 格式字符串

func (Carbon) ToTimeString added in v1.1.1

func (c Carbon) ToTimeString(timezone ...string) string

ToTimeString outputs a string in "15:04:05" layout. 输出 "15:04:05" 格式字符串

func (Carbon) ToUnixDateString added in v1.2.0

func (c Carbon) ToUnixDateString(timezone ...string) string

ToUnixDateString outputs a string in "Mon Jan _2 15:04:05 MST 2006" layout. 输出 "Mon Jan _2 15:04:05 MST 2006" 格式字符串

func (Carbon) ToW3cString added in v1.2.0

func (c Carbon) ToW3cString(timezone ...string) string

ToW3cString outputs a string in "2006-01-02T15:04:05Z07:00" layout. 输出 "2006-01-02T15:04:05Z07:00" 格式字符串

func (Carbon) ToWeekString added in v1.3.4

func (c Carbon) ToWeekString(timezone ...string) string

ToWeekString outputs a string in week layout like "Sunday", i18n is supported. 输出完整星期字符串,支持i18n

func (Carbon) Tomorrow added in v1.1.1

func (c Carbon) Tomorrow(timezone ...string) Carbon

Tomorrow returns a Carbon instance for tomorrow. 明天

func (Carbon) Value added in v1.1.1

func (c Carbon) Value() (driver.Value, error)

Value the interface providing the Value method for package database/sql/driver.

func (Carbon) Week added in v1.3.4

func (c Carbon) Week() int

Week gets current week like 6, start from 0. 获取当前周(从0开始)

func (Carbon) WeekOfMonth added in v1.2.0

func (c Carbon) WeekOfMonth() int

WeekOfMonth gets week of month like 1. 获取本月的第几周

func (Carbon) WeekOfYear added in v1.2.0

func (c Carbon) WeekOfYear() int

WeekOfYear gets week of year like 1, see https://en.wikipedia.org/wiki/ISO_8601#Week_dates. 获取本年的第几周

func (Carbon) Year added in v1.2.1

func (c Carbon) Year() int

Year gets current year like 2020. 获取当前年

func (Carbon) Yesterday added in v1.1.1

func (c Carbon) Yesterday(timezone ...string) Carbon

Yesterday returns a Carbon instance for yesterday. 昨天

type Date added in v1.5.2

type Date struct {
	Carbon
}

Date defines a Date struct.

func (Date) MarshalJSON added in v1.5.2

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

MarshalJSON implements the interface json.Marshal for Date struct.

func (*Date) UnmarshalJSON added in v1.5.2

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

UnmarshalJSON implements the interface json.Unmarshal for Date struct.

type DateTime added in v1.5.2

type DateTime struct {
	Carbon
}

DateTime defines a DateTime struct.

func (DateTime) MarshalJSON added in v1.5.2

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

MarshalJSON implements the interface json.Marshal for Date struct.

func (*DateTime) UnmarshalJSON added in v1.5.2

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

UnmarshalJSON implements the interface json.Unmarshal for Date struct.

type Language added in v1.3.1

type Language struct {
	Error error
	// contains filtered or unexported fields
}

Language define a Language struct. 定义 Language 结构体

func NewLanguage added in v1.3.1

func NewLanguage() *Language

NewLanguage return a new Language instance. 初始化 Language 结构体

func (*Language) SetLocale added in v1.3.1

func (lang *Language) SetLocale(locale string)

SetLocale sets language locale. 设置区域

func (*Language) SetResources added in v1.3.2

func (lang *Language) SetResources(resources map[string]string)

SetResources sets language resources. 设置资源

type Timestamp added in v1.5.2

type Timestamp struct {
	Carbon
}

Timestamp defines a Timestamp struct.

func (Timestamp) MarshalJSON added in v1.5.2

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

MarshalJSON implements the interface json.Marshal for Timestamp struct.

func (*Timestamp) UnmarshalJSON added in v1.5.2

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

UnmarshalJSON implements the interface json.Unmarshal for Timestamp struct.

type TimestampMicro added in v1.6.0

type TimestampMicro struct {
	Carbon
}

TimestampMicro defines a TimestampMicro struct.

func (TimestampMicro) MarshalJSON added in v1.6.0

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

MarshalJSON implements the interface MarshalJSON for TimestampMicro struct.

func (*TimestampMicro) UnmarshalJSON added in v1.6.0

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

UnmarshalJSON implements the interface json.Unmarshal for TimestampMicro struct.

type TimestampMilli added in v1.6.0

type TimestampMilli struct {
	Carbon
}

TimestampMilli defines a TimestampMilli struct.

func (TimestampMilli) MarshalJSON added in v1.6.0

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

MarshalJSON implements the interface json.Marshal for TimestampMilli struct.

func (*TimestampMilli) UnmarshalJSON added in v1.6.0

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

UnmarshalJSON implements the interface json.Unmarshal for TimestampMilli struct.

type TimestampNano added in v1.6.0

type TimestampNano struct {
	Carbon
}

TimestampNano defines a TimestampNano struct.

func (TimestampNano) MarshalJSON added in v1.6.0

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

MarshalJSON implements the interface json.Marshal for TimestampNano struct.

func (*TimestampNano) UnmarshalJSON added in v1.6.0

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

UnmarshalJSON implements the interface json.Unmarshal for TimestampNano struct.

Jump to

Keyboard shortcuts

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