carbon

package module
v2.3.11 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: MIT Imports: 14 Imported by: 1

README

Carbon

Carbon Release Go Test Go Report Card Go Coverage Goproxy.cn Carbon Doc License

English | 简体中文 | 日本語

Introduction

A simple, semantic and developer-friendly golang package for time, has been included by awesome-go

github.com/golang-module/carbon

gitee.com/golang-module/carbon

Installation
Go version >= 1.16 (recommend)
// 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/golang-module/carbon/v2

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

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

// By gitee
go get -u gitee.com/golang-module/carbon

import "gitee.com/golang-module/carbon"

Please refer to FAQ for the difference between v1 and v2, v1 is no longer updated, only maintained.

Usage and example

Assuming the current time is 2020-08-05 13:14:15.999999999 +0800 CST

Set globally default values
carbon.SetDefault(carbon.Default{
  Layout: carbon.DateTimeLayout,
  Timezone: carbon.Local,
  WeekStartsAt: carbon.Sunday,
  Locale: "en",
})

Suggest setting in the entry file such as main.go

Convert between Carbon and time.Time
// Convert standard Time.time to Carbon
carbon.CreateFromStdTime(time.Now())
// Convert Carbon to standard Time.time
carbon.Now().StdTime()
Yesterday, today and tomorrow
// Return datetime of today
fmt.Printf("%s", carbon.Now()) // 2020-08-05 13:14:15
carbon.Now().String() // 2020-08-05 13:14:15
carbon.Now().ToString() // 2020-08-05 13:14:15 +0800 CST
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() // 1596604455999
// Return timestamp with microsecond of today
carbon.Now().TimestampMicro() // 1596604455999999
// Return timestamp with nanosecond of today
carbon.Now().TimestampNano() // 1596604455999999999

// Return datetime of yesterday
fmt.Printf("%s", carbon.Yesterday()) // 2020-08-04 13:14:15
carbon.Yesterday().String() // 2020-08-04 13:14:15
carbon.Yesterday().ToString() // 2020-08-04 13:14:15 +0800 CST
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() // 1596518055999
// Return timestamp with microsecond of yesterday
carbon.Yesterday().TimestampMicro() // 1596518055999999
// Return timestamp with nanosecond of yesterday
carbon.Yesterday().TimestampNano() // 1596518055999999999

// Return datetime of tomorrow
fmt.Printf("%s", carbon.Tomorrow()) // 2020-08-06 13:14:15
carbon.Tomorrow().String() // 2020-08-06 13:14:15
carbon.Tomorrow().ToString() // 2020-08-06 13:14:15 +0800 CST
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() // 1596690855999
// Return timestamp with microsecond of tomorrow
carbon.Tomorrow().TimestampMicro() // 1596690855999999
// Return timestamp with nanosecond of tomorrow
carbon.Tomorrow().TimestampNano() // 1596690855999999999
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).ToString() // 2020-08-05 13:14:15 +0800 CST
// Create a Carbon instance from a given date and time with millisecond
carbon.CreateFromDateTimeMilli(2020, 8, 5, 13, 14, 15, 999).ToString() // 2020-08-05 13:14:15.999 +0800 CST
// Create a Carbon instance from a given date and time with microsecond
carbon.CreateFromDateTimeMicro(2020, 8, 5, 13, 14, 15, 999999).ToString() // 2020-08-05 13:14:15.999999 +0800 CST
// Create a Carbon instance from a given date and time with nanosecond
carbon.CreateFromDateTimeNano(2020, 8, 5, 13, 14, 15, 999999999).ToString() // 2020-08-05 13:14:15.999999999 +0800 CST

// Create a Carbon instance from a given year, month and day
carbon.CreateFromDate(2020, 8, 5).ToString() // 2020-08-05 00:00:00 +0800 CST
// Create a Carbon instance from a given year, month and day with millisecond
carbon.CreateFromDateMilli(2020, 8, 5, 999).ToString() // 2020-08-05 00:00:00.999 +0800 CST
// Create a Carbon instance from a given year, month and day with microsecond
carbon.CreateFromDateMicro(2020, 8, 5, 999999).ToString() // 2020-08-05 00:00:00.999999 +0800 CST
// Create a Carbon instance from a given year, month and day with nanosecond
carbon.CreateFromDateNano(2020, 8, 5, 999999999).ToString() // 2020-08-05 00:00:00.999999999 +0800 CST

// Create a Carbon instance from a given hour, minute and second
carbon.CreateFromTime(13, 14, 15).ToString() // 2020-08-05 13:14:15 +0800 CST
// Create a Carbon instance from a given hour, minute and second with millisecond
carbon.CreateFromTimeMilli(13, 14, 15, 999).ToString() // 2020-08-05 13:14:15.999 +0800 CST
// Create a Carbon instance from a given hour, minute and second with microsecond
carbon.CreateFromTimeMicro(13, 14, 15, 999999).ToString() // 2020-08-05 13:14:15.999999 +0800 CST
// Create a Carbon instance from a given hour, minute and second with nanosecond
carbon.CreateFromTimeNano(13, 14, 15, 999999999).ToString() // 2020-08-05 13:14:15.999999999 +0800 CST
Parse a time string as a Carbon instance
carbon.Parse("").ToDateTimeString() // empty string
carbon.Parse("0").ToDateTimeString() // empty string
carbon.Parse("00:00:00").ToDateTimeString() // empty string
carbon.Parse("0000-00-00").ToDateTimeString() // empty string
carbon.Parse("0000-00-00 00:00:00").ToDateTimeString() // empty string

carbon.Parse("now").ToString() // 2020-08-05 13:14:15 +0800 CST
carbon.Parse("yesterday").ToString() // 2020-08-04 13:14:15 +0800 CST
carbon.Parse("tomorrow").ToString() // 2020-08-06 13:14:15 +0800 CST

carbon.Parse("2020").ToString() // 2020-01-01 00:00:00 +0800 CST
carbon.Parse("2020-8").ToString() // 2020-08-01 00:00:00 +0800 CST
carbon.Parse("2020-08").ToString() // 2020-08-01 00:00:00 +0800 CST
carbon.Parse("2020-8-5").ToString() // 2020-08-05 00:00:00 +0800 CST
carbon.Parse("2020-8-05").ToString() // 2020-08-05 00:00:00 +0800 CST
carbon.Parse("2020-08-05").ToString() // 2020-08-05 00:00:00 +0800 CST
carbon.Parse("2020-08-05.999").ToString() // 2020-08-05 00:00:00.999 +0800 CST
carbon.Parse("2020-08-05.999999").ToString() // 2020-08-05 00:00:00.999999 +0800 CST
carbon.Parse("2020-08-05.999999999").ToString() // 2020-08-05 00:00:00.999999999 +0800 CST

carbon.Parse("2020-8-5 13:14:15").ToString() // 2020-08-05 13:14:15 +0800 CST
carbon.Parse("2020-8-05 13:14:15").ToString() // 2020-08-05 13:14:15 +0800 CST
carbon.Parse("2020-08-5 13:14:15").ToString() // 2020-08-05 13:14:15 +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-8-5T13:14:15+08:00").ToString() // 2020-08-05 13:14:15 +0800 CST
carbon.Parse("2020-8-05T13:14:15+08:00").ToString() // 2020-08-05 13:14:15 +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
carbon.Parse("20200805131415.999+08:00").ToString() // 2020-08-05 13:14:15.999 +0800 CST
carbon.Parse("20200805131415.999999+08:00").ToString() // 2020-08-05 13:14:15.999999 +0800 CST
carbon.Parse("20200805131415.999999999+08:00").ToString() // 2020-08-05 13:14:15.999999999 +0800 CST
Parse a time 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 time 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
Boundary
// 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().ToDateTimeString() // 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
Traveler
// 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-05-31 13:14:15").AddQuarters(3).ToDateTimeString() // 2020-03-02 13:14:15
// Add three quarters without overflowing month
carbon.Parse("2019-05-31 13:14:15").AddQuartersNoOverflow(3).ToDateTimeString() // 2020-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 duration
now := carbon.Now()
now.DiffInDuration(now).String() // 0s
now.AddHour().DiffInDuration(now).String() // 1h0m0s
now.SubHour().DiffInDuration(now).String() // -1h0m0s
// Difference in duration with absolute value
now.DiffAbsInDuration(now).String() // 0s
now.AddHour().DiffAbsInDuration(now).String() // 1h0m0s
now.SubHour().DiffAbsInDuration(now).String() // 1h0m0s

// 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
Extremum
c0 := carbon.Parse("2023-04-01")
c1 := carbon.Parse("2023-03-28")
c2 := carbon.Parse("2023-04-16")
// Return the closest Carbon instance
c0.Closest(c1, c2) // c1
// Return the farthest Carbon instance
c0.Farthest(c1, c2) // c2

yesterday := carbon.Yesterday()
today     := carbon.Now()
tomorrow  := carbon.Tomorrow()
// Return the maximum Carbon instance
carbon.Max(yesterday, today, tomorrow) // tomorrow
// Return the minimum Carbon instance
carbon.Min(yesterday, today, tomorrow) // yesterday
Comparison
// Whether is daylight saving time
carbon.Parse("").IsDST() // false
carbon.Parse("0").IsDST() // false
carbon.Parse("0000-00-00 00:00:00").IsDST() // false
carbon.Parse("0000-00-00").IsDST() // false
carbon.Parse("00:00:00").IsDST() // false
carbon.Parse("2023-01-01", "Australia/Brisbane").IsDST() // false
carbon.Parse("2023-01-01", "Australia/Sydney").IsDST() // true

// 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 before noon
carbon.Parse("2020-08-05 00:00:00").IsAM() // true
carbon.Parse("2020-08-05 08:00:00").IsAM() // true
carbon.Parse("2020-08-05 12:00:00").IsAM() // false
carbon.Parse("2020-08-05 13:00:00").IsAM() // false
// Whether is after noon
carbon.Parse("2020-08-05 00:00:00").IsPM() // false
carbon.Parse("2020-08-05 08:00:00").IsPM() // false
carbon.Parse("2020-08-05 12:00:00").IsPM() // true
carbon.Parse("2020-08-05 13:00:00").IsPM() // 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 is same century
carbon.Parse("2020-08-05 13:14:15").IsSameCentury(carbon.Parse("3020-08-05 13:14:15")) // false
carbon.Parse("2020-08-05 13:14:15").IsSameCentury(carbon.Parse("2099-08-05 13:14:15")) // true
// Whether is same decade
carbon.Parse("2020-08-05 13:14:15").IsSameDecade(carbon.Parse("2030-08-05 13:14:15")) // false
carbon.Parse("2020-08-05 13:14:15").IsSameDecade(carbon.Parse("2120-08-05 13:14:15")) // true
// Whether is same year
carbon.Parse("2020-08-05 00:00:00").IsSameYear(carbon.Parse("2021-08-05 13:14:15")) // false
carbon.Parse("2020-01-01 00:00:00").IsSameYear(carbon.Parse("2020-12-31 13:14:15")) // true
// Whether is same quarter
carbon.Parse("2020-08-05 00:00:00").IsSameQuarter(carbon.Parse("2020-09-05 13:14:15")) // false
carbon.Parse("2020-01-01 00:00:00").IsSameQuarter(carbon.Parse("2021-01-31 13:14:15")) // true
// Whether is same month
carbon.Parse("2020-01-01 00:00:00").IsSameMonth(carbon.Parse("2021-01-31 13:14:15")) // false
carbon.Parse("2020-01-01 00:00:00").IsSameMonth(carbon.Parse("2020-01-31 13:14:15")) // true
// Whether is same day
carbon.Parse("2020-08-05 13:14:15").IsSameDay(carbon.Parse("2021-08-05 13:14:15")) // false
carbon.Parse("2020-08-05 00:00:00").IsSameDay(carbon.Parse("2020-08-05 13:14:15")) // true
// Whether is same hour
carbon.Parse("2020-08-05 13:14:15").IsSameHour(carbon.Parse("2021-08-05 13:14:15")) // false
carbon.Parse("2020-08-05 13:00:00").IsSameHour(carbon.Parse("2020-08-05 13:14:15")) // true
// Whether is same minute
carbon.Parse("2020-08-05 13:14:15").IsSameMinute(carbon.Parse("2021-08-05 13:14:15")) // false
carbon.Parse("2020-08-05 13:14:00").IsSameMinute(carbon.Parse("2020-08-05 13:14:15")) // true
// Whether is same second
carbon.Parse("2020-08-05 13:14:15").IsSameSecond(carbon.Parse("2021-08-05 13:14:15")) // false
carbon.Parse("2020-08-05 13:14:15").IsSameSecond(carbon.Parse("2020-08-05 13:14:15")) // 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 location
utc, _ := time.LoadLocation(carbon.UTC)
carbon.SetLocation(utc).Now().ToDateTimeString() // 2022-06-28 09:25:38
tokyo, _ := time.LoadLocation(carbon.Tokyo)
carbon.SetLocation(tokyo).Now().ToDateTimeString() // 2022-06-28 18:25:38

// 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, second and 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, second and 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, second and 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).ToString() // 2019-02-02 00:00:00 +0800 CST
carbon.Parse("2020-01-01").SetDate(2019, 2, 31).ToString() // 2019-03-03 00:00:00 +0800 CST
// Set year, month, day and millisecond
carbon.Parse("2020-01-01").SetDateMilli(2019, 2, 2, 999).ToString() // 2019-02-02 00:00:00.999 +0800 CST
carbon.Parse("2020-01-01").SetDateMilli(2019, 2, 31, 999).ToString() // 2019-03-03 00:00:00.999 +0800 CST
// Set year, month, day and microsecond
carbon.Parse("2020-01-01").SetDateMicro(2019, 2, 2, 999999).ToString() // 2019-02-02 00:00:00.999999 +0800 CST
carbon.Parse("2020-01-01").SetDateMicro(2019, 2, 31, 999999).ToString() // 2019-03-03 00:00:00.999999 +0800 CST
// Set year, month, day and nanosecond
carbon.Parse("2020-01-01").SetDateNano(2019, 2, 2, 999999999).ToString() // 2019-02-02 00:00:00.999999999 +0800 CST
carbon.Parse("2020-01-01").SetDateNano(2019, 2, 31, 999999999).ToString() // 2019-03-03 00:00:00.999999999 +0800 CST

// Set hour, minute and second
carbon.Parse("2020-01-01").SetTime(13, 14, 15).ToString() // 2020-01-01 13:14:15 +0800 CST
carbon.Parse("2020-01-01").SetTime(13, 14, 90).ToString() // 2020-01-01 13:15:30 +0800 CST
// Set hour, minute, second and millisecond
carbon.Parse("2020-01-01").SetTimeMilli(13, 14, 15, 999).ToString() // 2020-01-01 13:14:15.999 +0800 CST
carbon.Parse("2020-01-01").SetTimeMilli(13, 14, 90, 999).ToString() // 2020-01-01 13:15:30.999 +0800 CST
// Set hour, minute, second and microsecond
carbon.Parse("2020-01-01").SetTimeMicro(13, 14, 15, 999999).ToString() // 2020-01-01 13:14:15.999999 +0800 CST
carbon.Parse("2020-01-01").SetTimeMicro(13, 14, 90, 999999).ToString() // 2020-01-01 13:15:30.999999 +0800 CST
// Set hour, minute, second and nanosecond
carbon.Parse("2020-01-01").SetTimeNano(13, 14, 15, 999999999).ToString() // 2020-01-01 13:14:15.999999999 +0800 CST
carbon.Parse("2020-01-01").SetTimeNano(13, 14, 90, 999999999).ToString() // 2020-01-01 13:15:30.999999999 +0800 CST

// 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 datetime format string
carbon.Parse("2020-08-05 13:14:15").ToDateTimeString() // 2020-08-05 13:14:15
// Output datetime with millisecond format string
carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToDateTimeMilliString() // 2020-08-05 13:14:15.999
// Output datetime with microsecond format string
carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToDateTimeMicroString() // 2020-08-05 13:14:15.999999
// Output datetime with nanosecond format string
carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToDateTimeNanoString() // 2020-08-05 13:14:15.999999999

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

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

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

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

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

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

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

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

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

// Output datetime format string
fmt.Printf("%s", carbon.Parse("2020-08-05 13:14:15")) // 2020-08-05 13:14:15

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

// Output "Jan 2, 2006" format string
carbon.Parse("2020-08-05 13:14:15").ToFormattedDateString() // Aug 5, 2020
// Output "Mon, Jan 2, 2006" format string
carbon.Parse("2020-08-05 13:14:15").ToFormattedDayDateString() // Wed, Aug 5, 2020

// Output string by layout
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 string by format
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
JSON
Scene one: all time fields have the same format
carbon.SetDefault(carbon.Default{
  Layout: carbon.DateTimeLayout,
})

type Person struct {
  Name string `json:"name"`
  Age  int    `json:"age"`
  
  Field1 carbon.Carbon `json:"field1"`
  Field2 carbon.Carbon `json:"field2"`
  Field3 carbon.Carbon `json:"field3"`
  Field4 carbon.Carbon `json:"field4"`
  
  Field5 carbon.Carbon `json:"field5"`
  Field6 carbon.Carbon `json:"field6"`
  Field7 carbon.Carbon `json:"field7"`
  Field8 carbon.Carbon `json:"field8"`
}

now := carbon.Parse("2020-08-05 13:14:15", carbon.PRC)
person := Person {
  Name:   "gouguoyin",
  Age:    18,
  
  Field1: now,
  Field2: now,
  Field3: now,
  Field4: now,
  Field5: now,
  Field6: now,
  Field7: now,
  Field8: now,
}

data, marshalErr := json.Marshal(person)
if marshalErr != nil {
  // Error handle...
  log.Fatal(marshalErr)
}
fmt.Printf("%s", data)
// Output
{
  "name": "gouguoyin",
  "age": 18,
  "field1": "2020-08-05 13:14:15",
  "field2": "2020-08-05 13:14:15",
  "field3": "2020-08-05 13:14:15",
  "field4": "2020-08-05 13:14:15",
  "field5": "2020-08-05 13:14:15",
  "field6": "2020-08-05 13:14:15",
  "field7": "2020-08-05 13:14:15",
  "field8": "2020-08-05 13:14:15"
}

var person Person
unmarshalErr := json.Unmarshal(data, &person)
if unmarshalErr != nil {
  // Error handle...
  log.Fatal(unmarshalErr)
}

fmt.Printf("%s", person.Field1) // 2020-08-05 13:14:15
fmt.Printf("%s", person.Field2) // 2020-08-05 13:14:15
fmt.Printf("%s", person.Field3) // 2020-08-05 13:14:15
fmt.Printf("%s", person.Field4) // 2020-08-05 13:14:15

fmt.Printf("%s", person.Field5) // 2020-08-05 13:14:15
fmt.Printf("%s", person.Field6) // 2020-08-05 13:14:15
fmt.Printf("%s", person.Field7) // 2020-08-05 13:14:15
fmt.Printf("%s", person.Field8) // 2020-08-05 13:14:15
Scene two: different time fields have different formats

Please refer to here for all supported type values. If the carbon tag is not set, the default is layout:2006-01-02 15:04:05, if the tz tag is not set, the default is Local

type Person struct {
  Name string `json:"name"`
  Age  int    `json:"age"`
  
  Field1 carbon.Carbon `json:"field1"`
  
  Field2 carbon.Carbon `json:"field2" carbon:"type:date" tz:"PRC"`
  Field3 carbon.Carbon `json:"field3" carbon:"type:time" tz:"PRC"`
  Field4 carbon.Carbon `json:"field4" carbon:"type:dateTime" tz:"PRC"`
  // or
  Field2 carbon.Carbon `json:"field2" carbon:"layout:2006-01-02" tz:"PRC"`
  Field3 carbon.Carbon `json:"field3" carbon:"layout:15:04:05" tz:"PRC"`
  Field4 carbon.Carbon `json:"field4" carbon:"layout:2006-01-02 15:04:05" tz:"PRC"`
  // or
  Field2 carbon.Carbon `json:"field2" carbon:"format:Y-m-d" tz:"PRC"`
  Field3 carbon.Carbon `json:"field3" carbon:"format:H:i:s" tz:"PRC"`
  Field4 carbon.Carbon `json:"field4" carbon:"format:Y-m-d H:i:s" tz:"PRC"`
  
  Field5 carbon.Carbon `json:"field5" carbon:"type:timestamp" tz:"PRC"`
  Field6 carbon.Carbon `json:"field6" carbon:"type:timestampMilli" tz:"PRC"`
  Field7 carbon.Carbon `json:"field7" carbon:"type:timestampMicro" tz:"PRC"`
  Field8 carbon.Carbon `json:"field8" carbon:"type:timestampNano" tz:"PRC"`
}

now := Parse("2020-08-05 13:14:15", carbon.PRC)
person := Person {
  Name:   "gouguoyin",
  Age:    18,
  
  Field1: now,
  Field2: now,
  Field3: now,
  Field4: now,
  Field5: now,
  Field6: now,
  Field7: now,
  Field8: now,
}

loadErr := carbon.LoadTag(&person)
if loadErr != nil {
  // Error handle...
  log.Fatal(loadErr)
}
data, marshalErr := json.Marshal(person)
if marshalErr != nil {
  // Error handle...
  log.Fatal(marshalErr)
}
fmt.Printf("%s", data)
// Output
{
  "name": "gouguoyin",
  "age": 18,
  "field1": "2020-08-05 13:14:15",
  "field2": "2020-08-05",
  "field3": "13:14:15",
  "field4": "2020-08-05 13:14:15",
  "field5": 1596604455,
  "field6": 1596604455999,
  "field7": 1596604455999999,
  "field8": 1596604455999999999
}

var person Person

loadErr := carbon.LoadTag(&person)
if loadErr != nil {
  // Error handle...
  log.Fatal(loadErr)
}

unmarshalErr := json.Unmarshal(data, &person)
if unmarshalErr != nil {
  // Error handle...
  log.Fatal(unmarshalErr)
}

fmt.Printf("%s", person.Field1) // 2002-08-05 13:14:15
fmt.Printf("%s", person.Field2) // 2020-08-05
fmt.Printf("%s", person.Field3) // 13:14:15
fmt.Printf("%s", person.Field4) // 2002-08-05 13:14:15

fmt.Printf("%d", person.Field5) // 1596604455
fmt.Printf("%d", person.Field6) // 1596604455999
fmt.Printf("%d", person.Field7) // 1596604455999999
fmt.Printf("%d", person.Field8) // 1596604455999999999

Calendar

The following calendars are supported

I18n

The following languages are supported

The following methods are supported

  • Constellation():get constellation name, like Aries
  • Season():get season name, like Spring
  • DiffForHumans():get the difference with human-readable format string, like 1 year from now
  • ToMonthString():output month format string, like January
  • ToShortMonthString():output short month format string, like Jan
  • ToWeekString():output week format string, like Sunday
  • ToShortWeekString():output short week format string, like Sun
Set locale
lang := carbon.NewLanguage()
lang.SetLocale("en")

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

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

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

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

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
Testing
c := carbon.SetTimezone(carbon.UTC)

c.Now().ToDateString() // 2023-12-27
c.Now().IsSetTestNow() // false

c.SetTestNow(carbon.Parse("2020-08-05"))
c.Now().ToDateString() // 2020-08-05
c.Now().IsSetTestNow() // true

c.UnSetTestNow()
c.Now().ToDateString() // 2023-12-27
c.Now().IsSetTestNow() // false
Error

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

c := carbon.SetTimezone("xxx").Parse("2020-08-05")
if c.Error != nil {
  // Error handle...
  log.Fatal(c.Error)
}
// 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 format, no padding - 1-12 3
G Hour in 24-hour format, no padding - 0-23 15
h Hour in 12-hour format, padded to 2 2 00-11 03
H Hour in 24-hour format, 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
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 week of the year, padded to 2 2 01-52 01
N day of the week, padded to 2 2 01-07 02
L Whether it's a leap year 1 0-1 0
U Unix timestamp with seconds - - 1596604455
V Unix timestamp with millisecond - - 1596604455666
X Unix timestamp with microsecond - - 1596604455666666
Z Unix timestamp with nanoseconds - - 1596604455666666666
v Millisecond - 1-999 999
u Microsecond - 1-999999 999999
x Nanosecond - 1-999999999 999999999
w Day of the week 1 0-6 1
t Total days of the month 2 28-31 31
z Day of the year - 1-365 2
e Location - - America/New_York
Q Quarter 1 1-4 1
C Century - 0-99 21
FAQ

1、What is the difference between v1 and v2?

There is no difference between v1 and v2 of the API, but the implementation of the translation resource files in language.go is different. The v1 is implemented by the third-party extension library packr, and the v2 is implemented by the standard library embed after golang1.16. If your golang version is 1.16+, the v2 is recommended, otherwise, the v1 is required.

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" // 本地时间
	UTC   = "UTC"   // 世界协调时间
	GMT   = "GMT"   // 格林尼治标准时间
	CST   = "CST"   // 中国标准时间
	EET   = "EET"   // 欧洲东部标准时间
	WET   = "WET"   // 欧洲西部标准时间
	CET   = "CET"   // 欧洲中部标准时间
	EST   = "EST"   // 美国东部标准时间
	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"         // 哈尔滨
	Urumqi     = "Asia/Urumqi"         // 乌鲁木齐
	HongKong   = "Asia/Hong_Kong"      // 香港
	Macao      = "Asia/Macao"          // 澳门
	Taipei     = "Asia/Taipei"         // 台北
	Tokyo      = "Asia/Tokyo"          // 东京
	HoChiMinh  = "Asia/Ho_Chi_Minh"    // 胡志明
	Hanoi      = "Asia/Hanoi"          // 河内
	Saigon     = "Asia/Saigon"         // 西贡
	Seoul      = "Asia/Seoul"          // 首尔
	Pyongyang  = "Asia/Pyongyang"      // 平壤
	Bangkok    = "Asia/Bangkok"        // 曼谷
	Dubai      = "Asia/Dubai"          // 迪拜
	Qatar      = "Asia/Qatar"          // 卡塔尔
	Bangalore  = "Asia/Bangalore"      // 班加罗尔
	Kolkata    = "Asia/Kolkata"        // 加尔各答
	Mumbai     = "Asia/Mumbai"         // 孟买
	MexicoCity = "America/Mexico_City" // 墨西哥
	NewYork    = "America/New_York"    // 纽约
	LosAngeles = "America/Los_Angeles" // 洛杉矶
	Chicago    = "America/Chicago"     // 芝加哥
	SaoPaulo   = "America/Sao_Paulo"   // 圣保罗
	Moscow     = "Europe/Moscow"       // 莫斯科
	London     = "Europe/London"       // 伦敦
	Berlin     = "Europe/Berlin"       // 柏林
	Paris      = "Europe/Paris"        // 巴黎
	Rome       = "Europe/Rome"         // 罗马
	Sydney     = "Australia/Sydney"    // 悉尼
	Melbourne  = "Australia/Melbourne" // 墨尔本
	Darwin     = "Australia/Darwin"    // 达尔文
)

timezone constants 时区常量

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"  // 十二月
)

month constants 月份常量

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

week constants 星期常量

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

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

number constants 数字常量

View Source
const (
	AtomLayout     = RFC3339Layout
	ANSICLayout    = time.ANSIC
	CookieLayout   = "Monday, 02-Jan-2006 15:04:05 MST"
	KitchenLayout  = time.Kitchen
	RssLayout      = time.RFC1123Z
	RubyDateLayout = time.RubyDate
	UnixDateLayout = time.UnixDate
	W3cLayout      = RFC3339Layout

	RFC1036Layout      = "Mon, 02 Jan 06 15:04:05 -0700"
	RFC1123Layout      = time.RFC1123
	RFC1123ZLayout     = time.RFC1123Z
	RFC2822Layout      = time.RFC1123Z
	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"
	RFC7231Layout      = "Mon, 02 Jan 2006 15:04:05 MST"
	RFC822Layout       = time.RFC822
	RFC822ZLayout      = time.RFC822Z
	RFC850Layout       = time.RFC850

	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"

	ISO8601ZuluLayout      = "2006-01-02T15:04:05Z"
	ISO8601ZuluMilliLayout = "2006-01-02T15:04:05.999Z"
	ISO8601ZuluMicroLayout = "2006-01-02T15:04:05.999999Z"
	ISO8601ZuluNanoLayout  = "2006-01-02T15:04:05.999999999Z"

	FormattedDateLayout    = "Jan 2, 2006"
	FormattedDayDateLayout = "Mon, Jan 2, 2006"

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

layout constants 布局模板常量

View Source
const (
	AtomFormat     = "Y-m-d\\TH:i:sP"
	ANSICFormat    = "D M j H:i:s Y"
	CookieFormat   = "l, d-M-Y H:i:s T"
	KitchenFormat  = "g:iA"
	RssFormat      = "D, d M Y H:i:s O"
	RubyDateFormat = "D M d H:i:s O Y"
	UnixDateFormat = "D M j H:i:s T Y"

	RFC1036Format      = "D, d M y H:i:s O"
	RFC1123Format      = "D, d M Y H:i:s T"
	RFC1123ZFormat     = "D, d M Y H:i:s O"
	RFC2822Format      = "D, d M Y H:i:s O"
	RFC3339Format      = "Y-m-d\\TH:i:sP"
	RFC3339MilliFormat = "Y-m-d\\TH:i:s.vP"
	RFC3339MicroFormat = "Y-m-d\\TH:i:s.uP"
	RFC3339NanoFormat  = "Y-m-d\\TH:i:s.xP"
	RFC7231Format      = "D, d M Y H:i:s T"
	RFC822Format       = "d M y H:i T"
	RFC822ZFormat      = "d M y H:i O"
	RFC850Format       = "l, d-M-y H:i:s T"

	ISO8601Format      = "Y-m-d\\TH:i:sP"
	ISO8601MilliFormat = "Y-m-d\\TH:i:s.vP"
	ISO8601MicroFormat = "Y-m-d\\TH:i:s.uP"
	ISO8601NanoFormat  = "Y-m-d\\TH:i:s.xP"

	ISO8601ZuluFormat      = "Y-m-d\\TH:i:s\\Z"
	ISO8601ZuluMilliFormat = "Y-m-d\\TH:i:s.v\\Z"
	ISO8601ZuluMicroFormat = "Y-m-d\\TH:i:s.u\\Z"
	ISO8601ZuluNanoFormat  = "Y-m-d\\TH:i:s.x\\Z"

	FormattedDateFormat    = "M j, Y"
	FormattedDayDateFormat = "D, M j, Y"

	DayDateTimeFormat        = "D, M j, Y g:i A"
	DateTimeFormat           = "Y-m-d H:i:s"
	DateTimeMilliFormat      = "Y-m-d H:i:s.v"
	DateTimeMicroFormat      = "Y-m-d H:i:s.u"
	DateTimeNanoFormat       = "Y-m-d H:i:s.x"
	ShortDateTimeFormat      = "YmdHis"
	ShortDateTimeMilliFormat = "YmdHis.v"
	ShortDateTimeMicroFormat = "YmdHis.u"
	ShortDateTimeNanoFormat  = "YmdHis.x"

	DateFormat           = "Y-m-d"
	DateMilliFormat      = "Y-m-d.v"
	DateMicroFormat      = "Y-m-d.u"
	DateNanoFormat       = "Y-m-d.x"
	ShortDateFormat      = "Ymd"
	ShortDateMilliFormat = "Ymd.v"
	ShortDateMicroFormat = "Ymd.u"
	ShortDateNanoFormat  = "Ymd.x"

	TimeFormat           = "H:i:s"
	TimeMilliFormat      = "H:i:s.v"
	TimeMicroFormat      = "H:i:s.u"
	TimeNanoFormat       = "H:i:s.x"
	ShortTimeFormat      = "His"
	ShortTimeMilliFormat = "His.v"
	ShortTimeMicroFormat = "His.u"
	ShortTimeNanoFormat  = "His.x"
)

format constants 格式模板常量

View Source
const Version = "2.3.11"

Version current version 当前版本号

Variables

This section is empty.

Functions

func LoadTag added in v2.3.0

func LoadTag(v interface{}) error

LoadTag loads tag. 加载标签

func SetDefault added in v2.3.4

func SetDefault(d Default)

SetDefault sets default. 设置全局默认值

Types

type Carbon

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

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

func CreateFromDate

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

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

func CreateFromDateMicro

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

CreateFromDateMicro creates a Carbon instance from a given date and microsecond. 从给定的年、月、日、微秒创建 Carbon 实例

func CreateFromDateMilli

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

CreateFromDateMilli creates a Carbon instance from a given date and millisecond. 从给定的年、月、日、毫秒创建 Carbon 实例

func CreateFromDateNano

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

CreateFromDateNano creates a Carbon instance from a given date and nanosecond. 从给定的年、月、日、纳秒创建 Carbon 实例

func CreateFromDateTime

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

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

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

func CreateFromDateTimeMilli

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

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

func CreateFromDateTimeNano

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

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

func CreateFromJulian added in v2.3.7

func CreateFromJulian(f float64) Carbon

CreateFromJulian creates a Carbon instance from Julian Day or Modified Julian Day. 从 儒略日/简化儒略日 创建 Carbon 实例

func CreateFromLunar added in v2.3.6

func CreateFromLunar(year, month, day, hour, minute, second int, isLeapMonth bool) Carbon

CreateFromLunar creates a Carbon instance from Lunar date and time. 从 农历日期 创建 Carbon 实例

func CreateFromPersian added in v2.3.8

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

CreateFromPersian creates a Carbon instance from Persian date and time. 从 波斯日期 创建 Carbon 实例

func CreateFromStdTime added in v2.2.4

func CreateFromStdTime(tt time.Time, timezone ...string) Carbon

CreateFromStdTime creates a Carbon instance from standard time.Time. 从标准的 time.Time 创建 Carbon 实例

func CreateFromTime

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

CreateFromTime creates a Carbon instance from a given time(year, month and day are taken from the current time). 从给定的时、分、秒创建 Carbon 实例(年、月、日取自当前时间)

func CreateFromTimeMicro

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

CreateFromTimeMicro creates a Carbon instance from a given time and microsecond(year, month and day are taken from the current time). 从给定的时、分、秒、微秒创建 Carbon 实例(年、月、日取自当前时间)

func CreateFromTimeMilli

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

CreateFromTimeMilli creates a Carbon instance from a given time and millisecond(year, month and day are taken from the current time). 从给定的时、分、秒、毫秒创建 Carbon 实例(年、月、日取自当前时间)

func CreateFromTimeNano

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

CreateFromTimeNano creates a Carbon instance from a given time and nanosecond(year, month and day are taken from the current time). 从给定的时、分、秒、纳秒创建 Carbon 实例(年、月、日取自当前时间)

func CreateFromTimestamp

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

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

func CreateFromTimestampMicro

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

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

func CreateFromTimestampMilli

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

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

func CreateFromTimestampNano

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

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

func Max added in v2.3.5

func Max(c1 Carbon, c2 ...Carbon) (c Carbon)

Max returns the maximum Carbon instance from the given Carbon instance (second-precision). 返回最大的 Carbon 实例

func Min added in v2.3.5

func Min(c1 Carbon, c2 ...Carbon) (c Carbon)

Min returns the minimum Carbon instance from the given Carbon instance (second-precision). 返回最小的 Carbon 实例

func NewCarbon

func NewCarbon() Carbon

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

func Now

func Now(timezone ...string) Carbon

Now returns a Carbon instance for now. 当前

func Parse

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

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

func ParseByFormat

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

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

func ParseByLayout

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

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

func SetLanguage

func SetLanguage(lang *Language) Carbon

SetLanguage sets language. 设置语言对象

func SetLocale

func SetLocale(locale string) Carbon

SetLocale sets locale. 设置语言区域

func SetLocation added in v2.1.9

func SetLocation(loc *time.Location) Carbon

SetLocation sets location. 设置地区

func SetTimezone

func SetTimezone(name string) Carbon

SetTimezone sets timezone. 设置时区

func SetWeekStartsAt added in v2.3.5

func SetWeekStartsAt(day string) Carbon

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

func Tomorrow

func Tomorrow(timezone ...string) Carbon

Tomorrow returns a Carbon instance for tomorrow. 明天

func Yesterday

func Yesterday(timezone ...string) Carbon

Yesterday returns a Carbon instance for yesterday. 昨天

func (Carbon) AddCenturies

func (c Carbon) AddCenturies(centuries int) Carbon

AddCenturies adds some centuries. N个世纪后

func (Carbon) AddCenturiesNoOverflow

func (c Carbon) AddCenturiesNoOverflow(centuries int) Carbon

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

func (Carbon) AddCentury

func (c Carbon) AddCentury() Carbon

AddCentury adds one century. 1个世纪后

func (Carbon) AddCenturyNoOverflow

func (c Carbon) AddCenturyNoOverflow() Carbon

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

func (Carbon) AddDay

func (c Carbon) AddDay() Carbon

AddDay adds one day. 1天后

func (Carbon) AddDays

func (c Carbon) AddDays(days int) Carbon

AddDays adds some days. N天后

func (Carbon) AddDecade

func (c Carbon) AddDecade() Carbon

AddDecade adds one decade. 1个年代后

func (Carbon) AddDecadeNoOverflow

func (c Carbon) AddDecadeNoOverflow() Carbon

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

func (Carbon) AddDecades

func (c Carbon) AddDecades(decades int) Carbon

AddDecades adds some decades. N个年代后

func (Carbon) AddDecadesNoOverflow

func (c Carbon) AddDecadesNoOverflow(decades int) Carbon

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

func (Carbon) AddDuration

func (c Carbon) AddDuration(duration string) Carbon

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

func (Carbon) AddHour

func (c Carbon) AddHour() Carbon

AddHour adds one hour. 1小时后

func (Carbon) AddHours

func (c Carbon) AddHours(hours int) Carbon

AddHours adds some hours. N小时后

func (Carbon) AddMicrosecond

func (c Carbon) AddMicrosecond() Carbon

AddMicrosecond adds one microsecond. 1微秒后

func (Carbon) AddMicroseconds

func (c Carbon) AddMicroseconds(microseconds int) Carbon

AddMicroseconds adds some microseconds. N微秒后

func (Carbon) AddMillisecond

func (c Carbon) AddMillisecond() Carbon

AddMillisecond adds one millisecond. 1毫秒后

func (Carbon) AddMilliseconds

func (c Carbon) AddMilliseconds(milliseconds int) Carbon

AddMilliseconds adds some milliseconds. N毫秒后

func (Carbon) AddMinute

func (c Carbon) AddMinute() Carbon

AddMinute adds one minute. 1分钟后

func (Carbon) AddMinutes

func (c Carbon) AddMinutes(minutes int) Carbon

AddMinutes adds some minutes. N分钟后

func (Carbon) AddMonth

func (c Carbon) AddMonth() Carbon

AddMonth adds one month. 1个月后

func (Carbon) AddMonthNoOverflow

func (c Carbon) AddMonthNoOverflow() Carbon

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

func (Carbon) AddMonths

func (c Carbon) AddMonths(months int) Carbon

AddMonths adds some months. N个月后

func (Carbon) AddMonthsNoOverflow

func (c Carbon) AddMonthsNoOverflow(months int) Carbon

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

func (Carbon) AddNanosecond

func (c Carbon) AddNanosecond() Carbon

AddNanosecond adds one nanosecond. 1纳秒后

func (Carbon) AddNanoseconds

func (c Carbon) AddNanoseconds(nanoseconds int) Carbon

AddNanoseconds adds some nanoseconds. N纳秒后

func (Carbon) AddQuarter

func (c Carbon) AddQuarter() Carbon

AddQuarter adds one quarter 1个季度后

func (Carbon) AddQuarterNoOverflow

func (c Carbon) AddQuarterNoOverflow() Carbon

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

func (Carbon) AddQuarters

func (c Carbon) AddQuarters(quarters int) Carbon

AddQuarters adds some quarters N个季度后

func (Carbon) AddQuartersNoOverflow

func (c Carbon) AddQuartersNoOverflow(quarters int) Carbon

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

func (Carbon) AddSecond

func (c Carbon) AddSecond() Carbon

AddSecond adds one second. 1秒钟后

func (Carbon) AddSeconds

func (c Carbon) AddSeconds(seconds int) Carbon

AddSeconds adds some seconds. N秒钟后

func (Carbon) AddWeek

func (c Carbon) AddWeek() Carbon

AddWeek adds one week. 1周后

func (Carbon) AddWeeks

func (c Carbon) AddWeeks(weeks int) Carbon

AddWeeks adds some weeks. N周后

func (Carbon) AddYear

func (c Carbon) AddYear() Carbon

AddYear adds one year. 1年后

func (Carbon) AddYearNoOverflow

func (c Carbon) AddYearNoOverflow() Carbon

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

func (Carbon) AddYears

func (c Carbon) AddYears(years int) Carbon

AddYears adds some years. N年后

func (Carbon) AddYearsNoOverflow

func (c Carbon) AddYearsNoOverflow(years int) Carbon

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

func (Carbon) Age

func (c Carbon) Age() int

Age gets age like 18. 获取年龄

func (Carbon) Between

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

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

func (Carbon) BetweenIncludedBoth

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

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

func (Carbon) BetweenIncludedEnd

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

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

func (Carbon) BetweenIncludedStart

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

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

func (Carbon) Century

func (c Carbon) Century() int

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

func (Carbon) Closest added in v2.2.13

func (c Carbon) Closest(c1 Carbon, c2 Carbon) Carbon

Closest returns the closest Carbon instance from the given Carbon instance. 返回离给定 carbon 实例最近的 Carbon 实例

func (Carbon) Compare

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

Compare compares by an operator. 时间比较

func (Carbon) Constellation

func (c Carbon) Constellation() string

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

func (Carbon) CreateFromDate

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

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

func (Carbon) CreateFromDateMicro

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

CreateFromDateMicro creates a Carbon instance from a given date and microsecond. 从给定的年、月、日、微秒创建 Carbon 实例

func (Carbon) CreateFromDateMilli

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

CreateFromDateMilli creates a Carbon instance from a given date and millisecond. 从给定的年、月、日、毫秒创建 Carbon 实例

func (Carbon) CreateFromDateNano

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

CreateFromDateNano creates a Carbon instance from a given date and nanosecond. 从给定的年、月、日、纳秒创建 Carbon 实例

func (Carbon) CreateFromDateTime

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

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

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

func (Carbon) CreateFromDateTimeMilli

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

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

func (Carbon) CreateFromDateTimeNano

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

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

func (Carbon) CreateFromTime

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

CreateFromTime creates a Carbon instance from a given time(year, month and day are taken from the current time). 从给定的时、分、秒创建 Carbon 实例(年、月、日取自当前时间)

func (Carbon) CreateFromTimeMicro

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

CreateFromTimeMicro creates a Carbon instance from a given time and microsecond(year, month and day are taken from the current time). 从给定的时、分、秒、微秒创建 Carbon 实例(年、月、日取自当前时间)

func (Carbon) CreateFromTimeMilli

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

CreateFromTimeMilli creates a Carbon instance from a given time and millisecond(year, month and day are taken from the current time). 从给定的时、分、秒、毫秒创建 Carbon 实例(年、月、日取自当前时间)

func (Carbon) CreateFromTimeNano

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

CreateFromTimeNano creates a Carbon instance from a given time and nanosecond(year, month and day are taken from the current time). 从给定的时、分、秒、纳秒创建 Carbon 实例(年、月、日取自当前时间)

func (Carbon) CreateFromTimestamp

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

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

func (Carbon) CreateFromTimestampMicro

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

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

func (Carbon) CreateFromTimestampMilli

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

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

func (Carbon) CreateFromTimestampNano

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

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

func (Carbon) Date

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

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

func (Carbon) DateMicro

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

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

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

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

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

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

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

func (c Carbon) Day() int

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

func (Carbon) DayOfMonth

func (c Carbon) DayOfMonth() int

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

func (Carbon) DayOfWeek

func (c Carbon) DayOfWeek() int

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

func (Carbon) DayOfYear

func (c Carbon) DayOfYear() int

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

func (Carbon) DaysInMonth

func (c Carbon) DaysInMonth() int

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

func (Carbon) DaysInYear

func (c Carbon) DaysInYear() int

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

func (Carbon) Decade

func (c Carbon) Decade() int

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

func (Carbon) DiffAbsInDays

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

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

func (Carbon) DiffAbsInDuration added in v2.3.10

func (c Carbon) DiffAbsInDuration(carbon ...Carbon) time.Duration

DiffAbsInDuration gets the difference in duration with absolute value. 相差时长(绝对值)

func (Carbon) DiffAbsInHours

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

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

func (Carbon) DiffAbsInMinutes

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

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

func (Carbon) DiffAbsInMonths

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

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

func (Carbon) DiffAbsInSeconds

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

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

func (Carbon) DiffAbsInString

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

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

func (Carbon) DiffAbsInWeeks

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

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

func (Carbon) DiffAbsInYears

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

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

func (Carbon) DiffForHumans

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

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

func (Carbon) DiffInDays

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

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

func (Carbon) DiffInDuration added in v2.3.10

func (c Carbon) DiffInDuration(carbon ...Carbon) time.Duration

DiffInDuration gets the difference in duration. 相差时长

func (Carbon) DiffInHours

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

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

func (Carbon) DiffInMinutes

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

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

func (Carbon) DiffInMonths

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

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

func (Carbon) DiffInSeconds

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

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

func (Carbon) DiffInString

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

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

func (Carbon) DiffInWeeks

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

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

func (Carbon) DiffInYears

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

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

func (Carbon) EndOfCentury

func (c Carbon) EndOfCentury() Carbon

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

func (Carbon) EndOfDay

func (c Carbon) EndOfDay() Carbon

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

func (Carbon) EndOfDecade

func (c Carbon) EndOfDecade() Carbon

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

func (Carbon) EndOfHour

func (c Carbon) EndOfHour() Carbon

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

func (Carbon) EndOfMinute

func (c Carbon) EndOfMinute() Carbon

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

func (Carbon) EndOfMonth

func (c Carbon) EndOfMonth() Carbon

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

func (Carbon) EndOfQuarter

func (c Carbon) EndOfQuarter() Carbon

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

func (Carbon) EndOfSeason

func (c Carbon) EndOfSeason() Carbon

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

func (Carbon) EndOfSecond

func (c Carbon) EndOfSecond() Carbon

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

func (Carbon) EndOfWeek

func (c Carbon) EndOfWeek() Carbon

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

func (Carbon) EndOfYear

func (c Carbon) EndOfYear() Carbon

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

func (Carbon) Eq

func (c Carbon) Eq(t Carbon) bool

Eq reports whether equal. 是否等于

func (Carbon) Farthest added in v2.2.13

func (c Carbon) Farthest(c1 Carbon, c2 Carbon) Carbon

Farthest returns the farthest Carbon instance from the given Carbon instance. 返回离给定 carbon 实例最远的 Carbon 实例

func (Carbon) Format

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

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

func (Carbon) GoString added in v2.3.10

func (c Carbon) GoString() string

GoString implements fmt.GoStringer and formats c to be printed in Go source code. 实现 fmt.GoStringer 接口,并格式化 c 以在 Go 源代码中打印

func (Carbon) GormDataType added in v2.3.0

func (c Carbon) GormDataType() string

GormDataType implements the interface GormDataTypeInterface for Carbon struct. 实现 GormDataTypeInterface 接口

func (Carbon) Gt

func (c Carbon) Gt(t Carbon) bool

Gt reports whether greater than. 是否大于

func (Carbon) Gte

func (c Carbon) Gte(t Carbon) bool

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

func (Carbon) Hour

func (c Carbon) Hour() int

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

func (Carbon) IsAM added in v2.3.5

func (c Carbon) IsAM() bool

IsAM reports whether is before noon. 是否是上午

func (Carbon) IsApril

func (c Carbon) IsApril() bool

IsApril reports whether is April. 是否是四月

func (Carbon) IsAquarius

func (c Carbon) IsAquarius() bool

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

func (Carbon) IsAries

func (c Carbon) IsAries() bool

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

func (Carbon) IsAugust

func (c Carbon) IsAugust() bool

IsAugust reports whether is August. 是否是八月

func (Carbon) IsAutumn

func (c Carbon) IsAutumn() bool

IsAutumn reports whether is autumn. 是否是秋季

func (Carbon) IsCancer

func (c Carbon) IsCancer() bool

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

func (Carbon) IsCapricorn

func (c Carbon) IsCapricorn() bool

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

func (Carbon) IsDST added in v2.2.13

func (c Carbon) IsDST() bool

IsDST reports whether is daylight saving time. 是否是夏令时

func (Carbon) IsDecember

func (c Carbon) IsDecember() bool

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

func (Carbon) IsFebruary

func (c Carbon) IsFebruary() bool

IsFebruary reports whether is February. 是否是二月

func (Carbon) IsFriday

func (c Carbon) IsFriday() bool

IsFriday reports whether is Friday. 是否是周五

func (Carbon) IsFuture

func (c Carbon) IsFuture() bool

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

func (Carbon) IsGemini

func (c Carbon) IsGemini() bool

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

func (Carbon) IsInvalid

func (c Carbon) IsInvalid() bool

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

func (Carbon) IsJanuary

func (c Carbon) IsJanuary() bool

IsJanuary reports whether is January. 是否是一月

func (Carbon) IsJuly

func (c Carbon) IsJuly() bool

IsJuly reports whether is July. 是否是七月

func (Carbon) IsJune

func (c Carbon) IsJune() bool

IsJune reports whether is June. 是否是六月

func (Carbon) IsLeapYear

func (c Carbon) IsLeapYear() bool

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

func (Carbon) IsLeo

func (c Carbon) IsLeo() bool

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

func (Carbon) IsLibra

func (c Carbon) IsLibra() bool

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

func (Carbon) IsLongYear

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

func (c Carbon) IsMarch() bool

IsMarch reports whether is March. 是否是三月

func (Carbon) IsMay

func (c Carbon) IsMay() bool

IsMay reports whether is May. 是否是五月

func (Carbon) IsMonday

func (c Carbon) IsMonday() bool

IsMonday reports whether is Monday. 是否是周一

func (Carbon) IsNovember

func (c Carbon) IsNovember() bool

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

func (Carbon) IsNow

func (c Carbon) IsNow() bool

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

func (Carbon) IsOctober

func (c Carbon) IsOctober() bool

IsOctober reports whether is October. 是否是十月

func (Carbon) IsPM added in v2.3.5

func (c Carbon) IsPM() bool

IsPM reports whether is after noon. 是否是下午

func (Carbon) IsPast

func (c Carbon) IsPast() bool

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

func (Carbon) IsPisces

func (c Carbon) IsPisces() bool

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

func (Carbon) IsSagittarius

func (c Carbon) IsSagittarius() bool

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

func (Carbon) IsSameCentury added in v2.1.7

func (c Carbon) IsSameCentury(t Carbon) bool

IsSameCentury reports whether is same century. 是否是同一世纪

func (Carbon) IsSameDay added in v2.1.7

func (c Carbon) IsSameDay(t Carbon) bool

IsSameDay reports whether is same day. 是否是同一天

func (Carbon) IsSameDecade added in v2.1.7

func (c Carbon) IsSameDecade(t Carbon) bool

IsSameDecade reports whether is same decade. 是否是同一年代

func (Carbon) IsSameHour added in v2.1.7

func (c Carbon) IsSameHour(t Carbon) bool

IsSameHour reports whether is same hour. 是否是同一小时

func (Carbon) IsSameMinute added in v2.1.7

func (c Carbon) IsSameMinute(t Carbon) bool

IsSameMinute reports whether is same minute. 是否是同一分钟

func (Carbon) IsSameMonth added in v2.1.7

func (c Carbon) IsSameMonth(t Carbon) bool

IsSameMonth reports whether is same month. 是否是同一月

func (Carbon) IsSameQuarter added in v2.1.7

func (c Carbon) IsSameQuarter(t Carbon) bool

IsSameQuarter reports whether is same quarter. 是否是同一季节

func (Carbon) IsSameSecond added in v2.1.7

func (c Carbon) IsSameSecond(t Carbon) bool

IsSameSecond reports whether is same second. 是否是同一秒

func (Carbon) IsSameYear added in v2.1.7

func (c Carbon) IsSameYear(t Carbon) bool

IsSameYear reports whether is same year. 是否是同一年

func (Carbon) IsSaturday

func (c Carbon) IsSaturday() bool

IsSaturday reports whether is Saturday. 是否是周六

func (Carbon) IsScorpio

func (c Carbon) IsScorpio() bool

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

func (Carbon) IsSeptember

func (c Carbon) IsSeptember() bool

IsSeptember reports whether is September. 是否是九月

func (Carbon) IsSetTestNow added in v2.3.1

func (c Carbon) IsSetTestNow() bool

IsSetTestNow report whether there is testing time now. 是否设置过当前测试时间

func (Carbon) IsSpring

func (c Carbon) IsSpring() bool

IsSpring reports whether is spring. 是否是春季

func (Carbon) IsSummer

func (c Carbon) IsSummer() bool

IsSummer reports whether is summer. 是否是夏季

func (Carbon) IsSunday

func (c Carbon) IsSunday() bool

IsSunday reports whether is Sunday. 是否是周日

func (Carbon) IsTaurus

func (c Carbon) IsTaurus() bool

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

func (Carbon) IsThursday

func (c Carbon) IsThursday() bool

IsThursday reports whether is Thursday. 是否是周四

func (Carbon) IsToday

func (c Carbon) IsToday() bool

IsToday reports whether is today. 是否是今天

func (Carbon) IsTomorrow

func (c Carbon) IsTomorrow() bool

IsTomorrow reports whether is tomorrow. 是否是明天

func (Carbon) IsTuesday

func (c Carbon) IsTuesday() bool

IsTuesday reports whether is Tuesday. 是否是周二

func (Carbon) IsValid

func (c Carbon) IsValid() bool

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

func (Carbon) IsVirgo

func (c Carbon) IsVirgo() bool

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

func (Carbon) IsWednesday

func (c Carbon) IsWednesday() bool

IsWednesday reports whether is Wednesday. 是否是周三

func (Carbon) IsWeekday

func (c Carbon) IsWeekday() bool

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

func (Carbon) IsWeekend

func (c Carbon) IsWeekend() bool

IsWeekend reports whether is weekend. 是否是周末

func (Carbon) IsWinter

func (c Carbon) IsWinter() bool

IsWinter reports whether is winter. 是否是冬季

func (Carbon) IsYesterday

func (c Carbon) IsYesterday() bool

IsYesterday reports whether is yesterday. 是否是昨天

func (Carbon) IsZero

func (c Carbon) IsZero() bool

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

func (Carbon) Julian added in v2.3.7

func (c Carbon) Julian() (j julian.Julian)

Julian converts Carbon instance to Julian instance. 将 Carbon 实例转化为 Julian 实例

func (Carbon) Layout

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

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

func (Carbon) Locale

func (c Carbon) Locale() string

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

func (Carbon) Location

func (c Carbon) Location() string

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

func (Carbon) Lt

func (c Carbon) Lt(t Carbon) bool

Lt reports whether less than. 是否小于

func (Carbon) Lte

func (c Carbon) Lte(t Carbon) bool

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

func (Carbon) Lunar

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

Lunar converts Carbon instance to Lunar instance. 将 Carbon 实例转化为 Lunar 实例

func (Carbon) MarshalJSON added in v2.3.0

func (c Carbon) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface. 实现 json.Marshaler 接口

func (Carbon) Microsecond

func (c Carbon) Microsecond() int

Microsecond gets current microsecond like 999999. 获取当前微秒数

func (Carbon) Millisecond

func (c Carbon) Millisecond() int

Millisecond gets current millisecond like 999. 获取当前毫秒数

func (Carbon) Minute

func (c Carbon) Minute() int

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

func (Carbon) Month

func (c Carbon) Month() int

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

func (Carbon) MonthOfYear

func (c Carbon) MonthOfYear() int

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

func (Carbon) Nanosecond

func (c Carbon) Nanosecond() int

Nanosecond gets current nanosecond like 999999999. 获取当前纳秒数

func (Carbon) Ne

func (c Carbon) Ne(t Carbon) bool

Ne reports whether not equal. 是否不等于

func (Carbon) Now

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

Now returns a Carbon instance for now. 当前

func (Carbon) Offset

func (c Carbon) Offset() int

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

func (Carbon) Parse

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

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

func (Carbon) ParseByFormat

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

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

func (Carbon) ParseByLayout

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

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

func (Carbon) Persian added in v2.3.8

func (c Carbon) Persian() (p persian.Persian)

Persian converts Carbon instance to Persian instance. 将 Carbon 实例转化为 Persian 实例

func (Carbon) Quarter

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

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

func (*Carbon) Scan

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

func (c Carbon) Season() string

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

func (Carbon) Second

func (c Carbon) Second() int

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

func (Carbon) SetDate

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

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

func (Carbon) SetDateMicro

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

SetDateMicro sets year, month, day and microsecond. 设置年、月、日、微秒

func (Carbon) SetDateMilli

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

SetDateMilli sets year, month, day and millisecond. 设置年、月、日、毫秒

func (Carbon) SetDateNano

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

SetDateNano sets year, month, day and nanosecond. 设置年、月、日、纳秒

func (Carbon) SetDateTime

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

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

func (Carbon) SetDateTimeMicro

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

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

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

func (c Carbon) SetDay(day int) Carbon

SetDay sets day. 设置日期

func (Carbon) SetHour

func (c Carbon) SetHour(hour int) Carbon

SetHour sets hour. 设置小时

func (Carbon) SetLocale

func (c Carbon) SetLocale(locale string) Carbon

SetLocale sets locale. 设置语言区域

func (Carbon) SetLocation added in v2.1.9

func (c Carbon) SetLocation(loc *time.Location) Carbon

SetLocation sets location. 设置地区

func (Carbon) SetMicrosecond

func (c Carbon) SetMicrosecond(microsecond int) Carbon

SetMicrosecond sets microsecond. 设置微秒

func (Carbon) SetMillisecond

func (c Carbon) SetMillisecond(millisecond int) Carbon

SetMillisecond sets millisecond. 设置毫秒

func (Carbon) SetMinute

func (c Carbon) SetMinute(minute int) Carbon

SetMinute sets minute. 设置分钟

func (Carbon) SetMonth

func (c Carbon) SetMonth(month int) Carbon

SetMonth sets month. 设置月份

func (Carbon) SetMonthNoOverflow

func (c Carbon) SetMonthNoOverflow(month int) Carbon

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

func (Carbon) SetNanosecond

func (c Carbon) SetNanosecond(nanosecond int) Carbon

SetNanosecond sets nanosecond. 设置纳秒

func (Carbon) SetSecond

func (c Carbon) SetSecond(second int) Carbon

SetSecond sets second. 设置秒数

func (Carbon) SetTag added in v2.3.0

func (c Carbon) SetTag(tag *tag) Carbon

SetTag sets tag. 设置标签

func (*Carbon) SetTestNow added in v2.2.5

func (c *Carbon) SetTestNow(carbon Carbon)

SetTestNow sets a test Carbon instance (real or mock) to be returned when a "now" instance is created. 设置当前测试时间

func (Carbon) SetTime

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

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

func (Carbon) SetTimeMicro

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

SetTimeMicro sets hour, minute, second and microsecond. 设置时、分、秒、微秒

func (Carbon) SetTimeMilli

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

SetTimeMilli sets hour, minute, second and millisecond. 设置时、分、秒、毫秒

func (Carbon) SetTimeNano

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

SetTimeNano sets hour, minute, second and nanosecond. 设置、时、分、秒、纳秒

func (Carbon) SetTimezone

func (c Carbon) SetTimezone(name string) Carbon

SetTimezone sets timezone. 设置时区

func (Carbon) SetWeekStartsAt

func (c Carbon) SetWeekStartsAt(day string) Carbon

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

func (Carbon) SetYear

func (c Carbon) SetYear(year int) Carbon

SetYear sets year. 设置年份

func (Carbon) SetYearNoOverflow

func (c Carbon) SetYearNoOverflow(year int) Carbon

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

func (Carbon) StartOfCentury

func (c Carbon) StartOfCentury() Carbon

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

func (Carbon) StartOfDay

func (c Carbon) StartOfDay() Carbon

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

func (Carbon) StartOfDecade

func (c Carbon) StartOfDecade() Carbon

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

func (Carbon) StartOfHour

func (c Carbon) StartOfHour() Carbon

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

func (Carbon) StartOfMinute

func (c Carbon) StartOfMinute() Carbon

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

func (Carbon) StartOfMonth

func (c Carbon) StartOfMonth() Carbon

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

func (Carbon) StartOfQuarter

func (c Carbon) StartOfQuarter() Carbon

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

func (Carbon) StartOfSeason

func (c Carbon) StartOfSeason() Carbon

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

func (Carbon) StartOfSecond

func (c Carbon) StartOfSecond() Carbon

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

func (Carbon) StartOfWeek

func (c Carbon) StartOfWeek() Carbon

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

func (Carbon) StartOfYear

func (c Carbon) StartOfYear() Carbon

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

func (Carbon) StdTime added in v2.3.8

func (c Carbon) StdTime() time.Time

StdTime gets standard time.Time. 获取标准 time.Time

func (Carbon) String

func (c Carbon) String() string

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

func (Carbon) SubCenturies

func (c Carbon) SubCenturies(centuries int) Carbon

SubCenturies subtracts some centuries. N个世纪前

func (Carbon) SubCenturiesNoOverflow

func (c Carbon) SubCenturiesNoOverflow(centuries int) Carbon

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

func (Carbon) SubCentury

func (c Carbon) SubCentury() Carbon

SubCentury subtracts one century. 1个世纪前

func (Carbon) SubCenturyNoOverflow

func (c Carbon) SubCenturyNoOverflow() Carbon

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

func (Carbon) SubDay

func (c Carbon) SubDay() Carbon

SubDay subtracts one day. 1天前

func (Carbon) SubDays

func (c Carbon) SubDays(days int) Carbon

SubDays subtracts some days. N天前

func (Carbon) SubDecade

func (c Carbon) SubDecade() Carbon

SubDecade subtracts one decade. 1个年代后

func (Carbon) SubDecadeNoOverflow

func (c Carbon) SubDecadeNoOverflow() Carbon

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

func (Carbon) SubDecades

func (c Carbon) SubDecades(decades int) Carbon

SubDecades subtracts some decades. N个年代后

func (Carbon) SubDecadesNoOverflow

func (c Carbon) SubDecadesNoOverflow(decades int) Carbon

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

func (Carbon) SubDuration

func (c Carbon) SubDuration(duration string) Carbon

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

func (Carbon) SubHour

func (c Carbon) SubHour() Carbon

SubHour subtracts one hour. 1小时前

func (Carbon) SubHours

func (c Carbon) SubHours(hours int) Carbon

SubHours subtracts some hours. N小时前

func (Carbon) SubMicrosecond

func (c Carbon) SubMicrosecond() Carbon

SubMicrosecond subtracts one microsecond. 1微秒前

func (Carbon) SubMicroseconds

func (c Carbon) SubMicroseconds(microseconds int) Carbon

SubMicroseconds subtracts some microseconds. N微秒前

func (Carbon) SubMillisecond

func (c Carbon) SubMillisecond() Carbon

SubMillisecond subtracts one millisecond. 1毫秒前

func (Carbon) SubMilliseconds

func (c Carbon) SubMilliseconds(milliseconds int) Carbon

SubMilliseconds subtracts some milliseconds. N毫秒前

func (Carbon) SubMinute

func (c Carbon) SubMinute() Carbon

SubMinute subtracts one minute. 1分钟前

func (Carbon) SubMinutes

func (c Carbon) SubMinutes(minutes int) Carbon

SubMinutes subtracts some minutes. N分钟前

func (Carbon) SubMonth

func (c Carbon) SubMonth() Carbon

SubMonth subtracts one month. 1个月前

func (Carbon) SubMonthNoOverflow

func (c Carbon) SubMonthNoOverflow() Carbon

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

func (Carbon) SubMonths

func (c Carbon) SubMonths(months int) Carbon

SubMonths subtracts some months. N个月前

func (Carbon) SubMonthsNoOverflow

func (c Carbon) SubMonthsNoOverflow(months int) Carbon

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

func (Carbon) SubNanosecond

func (c Carbon) SubNanosecond() Carbon

SubNanosecond subtracts one nanosecond. 1纳秒前

func (Carbon) SubNanoseconds

func (c Carbon) SubNanoseconds(nanoseconds int) Carbon

SubNanoseconds subtracts some nanoseconds. N纳秒前

func (Carbon) SubQuarter

func (c Carbon) SubQuarter() Carbon

SubQuarter subtracts one quarter. 1个季度前

func (Carbon) SubQuarterNoOverflow

func (c Carbon) SubQuarterNoOverflow() Carbon

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

func (Carbon) SubQuarters

func (c Carbon) SubQuarters(quarters int) Carbon

SubQuarters subtracts some quarters. N个季度前

func (Carbon) SubQuartersNoOverflow

func (c Carbon) SubQuartersNoOverflow(quarters int) Carbon

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

func (Carbon) SubSecond

func (c Carbon) SubSecond() Carbon

SubSecond subtracts one second. 1秒钟前

func (Carbon) SubSeconds

func (c Carbon) SubSeconds(seconds int) Carbon

SubSeconds subtracts some seconds. N秒钟前

func (Carbon) SubWeek

func (c Carbon) SubWeek() Carbon

SubWeek subtracts one week. 1周前

func (Carbon) SubWeeks

func (c Carbon) SubWeeks(weeks int) Carbon

SubWeeks subtracts some weeks. N周前

func (Carbon) SubYear

func (c Carbon) SubYear() Carbon

SubYear subtracts one year. 1年前

func (Carbon) SubYearNoOverflow

func (c Carbon) SubYearNoOverflow() Carbon

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

func (Carbon) SubYears

func (c Carbon) SubYears(years int) Carbon

SubYears subtracts some years. N年前

func (Carbon) SubYearsNoOverflow

func (c Carbon) SubYearsNoOverflow(years int) Carbon

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

func (Carbon) Time

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

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

func (Carbon) TimeMicro

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

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

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

func (c Carbon) Timestamp() int64

Timestamp gets timestamp with second like 1596604455. 输出秒级时间戳

func (Carbon) TimestampMicro

func (c Carbon) TimestampMicro() int64

TimestampMicro gets timestamp with microsecond like 1596604455000000. 获取微秒级时间戳

func (Carbon) TimestampMilli

func (c Carbon) TimestampMilli() int64

TimestampMilli gets timestamp with millisecond like 1596604455000. 获取毫秒级时间戳

func (Carbon) TimestampNano

func (c Carbon) TimestampNano() int64

TimestampNano gets timestamp with nanosecond like 1596604455000000000. 获取纳秒级时间戳

func (Carbon) Timezone

func (c Carbon) Timezone() string

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

func (Carbon) ToAnsicString added in v2.3.0

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

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

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

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

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

func (Carbon) ToDateMilliString

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

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

func (Carbon) ToDateNanoString

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

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

func (Carbon) ToDateString

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

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

func (Carbon) ToDateTimeMicroString

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

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

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

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

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) ToFormattedDateString added in v2.3.10

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

ToFormattedDateString outputs a string in "Jan 2, 2006" layout. 输出 "Jan 2, 2006" 格式字符串

func (Carbon) ToFormattedDayDateString added in v2.3.10

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

ToFormattedDayDateString outputs a string in "Mon, Jan 2, 2006" layout. 输出 "Jan 2, 2006" 格式字符串

func (Carbon) ToIso8601MicroString

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

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

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

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) ToIso8601ZuluMicroString added in v2.3.10

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

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

func (Carbon) ToIso8601ZuluMilliString added in v2.3.10

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

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

func (Carbon) ToIso8601ZuluNanoString added in v2.3.10

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

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

func (Carbon) ToIso8601ZuluString added in v2.3.10

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

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

func (Carbon) ToKitchenString

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

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

func (Carbon) ToMonthString

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

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

func (Carbon) ToRfc1036String

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

func (Carbon) ToShortDateMilliString

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

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

func (Carbon) ToShortDateNanoString

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

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

func (Carbon) ToShortDateString

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

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

func (Carbon) ToShortDateTimeMicroString

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

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

func (Carbon) ToShortDateTimeMilliString

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

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

func (Carbon) ToShortDateTimeNanoString

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

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

func (Carbon) ToShortDateTimeString

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

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

func (Carbon) ToShortMonthString

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

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

func (Carbon) ToShortTimeMicroString

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

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

func (Carbon) ToShortTimeMilliString

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

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

func (Carbon) ToShortTimeNanoString

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

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

func (Carbon) ToShortTimeString

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

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

func (Carbon) ToShortWeekString

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

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

func (Carbon) ToStdTime deprecated added in v2.2.3

func (c Carbon) ToStdTime() time.Time

Deprecated: it will be removed in the future, use StdTime instead.

ToStdTime converts Carbon to standard time.Time. 将 Carbon 转换成标准 time.Time

func (Carbon) ToString

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

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

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

func (Carbon) ToTimeMilliString

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

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

func (Carbon) ToTimeNanoString

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

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

func (Carbon) ToTimeString

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

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

func (Carbon) ToUnixDateString

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

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

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

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

func (Carbon) Tomorrow

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

Tomorrow returns a Carbon instance for tomorrow. 明天

func (*Carbon) UnSetTestNow added in v2.3.1

func (c *Carbon) UnSetTestNow()

UnSetTestNow clears a test Carbon instance (real or mock) to be returned when a "now" instance is created. 清除当前测试时间

func (*Carbon) UnmarshalJSON added in v2.3.0

func (c *Carbon) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface. 实现 json.Unmarshaler 接口

func (Carbon) Value

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

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

func (Carbon) Week

func (c Carbon) Week() int

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

func (Carbon) WeekOfMonth

func (c Carbon) WeekOfMonth() int

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

func (Carbon) WeekOfYear

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

func (c Carbon) Year() int

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

func (Carbon) Yesterday

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

Yesterday returns a Carbon instance for yesterday. 昨天

type Default added in v2.3.4

type Default struct {
	Layout       string
	Timezone     string
	WeekStartsAt string
	Locale       string
}

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

type Language

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

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

func NewLanguage

func NewLanguage() *Language

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

func (*Language) SetLocale

func (lang *Language) SetLocale(locale string) *Language

SetLocale sets language locale. 设置区域

func (*Language) SetResources

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

SetResources sets language resources. 设置资源

Directories

Path Synopsis
Package calendar is part of the carbon package.
Package calendar is part of the carbon package.
julian
Package julian is part of the carbon package.
Package julian is part of the carbon package.
lunar
Package lunar is part of the carbon package.
Package lunar is part of the carbon package.
persian
Package persian is part of the carbon package.
Package persian is part of the carbon package.

Jump to

Keyboard shortcuts

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