carbon

package module
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2021 License: MIT Imports: 7 Imported by: 169

README

Carbon

Carbon Release Build Status Go Report Card Go Code Coverage Carbon Doc License

English | 简体中文 | 日本語

Introduction

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

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

github:github.com/golang-module/carbon

gitee:gitee.com/go-package/carbon

Installation
// By github
go get -u github.com/golang-module/carbon

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

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

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

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

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

// Return datetime of yesterday 
fmt.Sprintf("%s", carbon.Yesterday()) // 2020-08-04 13:14:15
carbon.Yesterday().ToDateTimeString() // 2020-08-04 13:14:15
// Return date of yesterday
carbon.Yesterday().ToDateString() // 2020-08-04
// Return time of yesterday
carbon.Yesterday().ToTimeString() // 13:14:15
// Return timestamp with second of yesterday
carbon.Yesterday().ToTimestamp() // 1596518055
carbon.Yesterday().ToTimestampWithSecond() // 1596518055
// Return timestamp with millisecond of yesterday
carbon.Yesterday().ToTimestampWithMillisecond() // 1596518055000
// Return timestamp with microsecond of yesterday
carbon.Yesterday().ToTimestampWithMicrosecond() // 1596518055000000
// Return timestamp with nanosecond of yesterday
carbon.Yesterday().ToTimestampWithNanosecond() // 1596518055000000000
// 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
carbon.SetTimezone(Carbon.NewYork).Yesterday().ToDateTimeString() // 2020-08-04 14:14:15

// Return datetime of tomorrow
fmt.Sprintf("%s", carbon.Tomorrow()) // 2020-08-06 13:14:15
carbon.Tomorrow().ToDateTimeString() // 2020-08-06 13:14:15
// Return date of tomorrow
carbon.Tomorrow().ToDateString() // 2020-08-06
// Return time of tomorrow
carbon.Tomorrow().ToTimeString() // 13:14:15
// Return timestamp with second of tomorrow
carbon.Tomorrow().ToTimestamp() // 1596690855
carbon.Tomorrow().ToTimestampWithSecond() // 1596690855
// Return timestamp with millisecond of tomorrow
carbon.Tomorrow().ToTimestampWithMillisecond() // 1596690855000
// Return timestamp with microsecond of tomorrow
carbon.Tomorrow().ToTimestampWithMicrosecond() // 1596690855000000
// Return timestamp with nanosecond of tomorrow
carbon.Tomorrow().ToTimestampWithNanosecond() // 1596690855000000000
// 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
carbon.SetTimezone(Carbon.NewYork).Tomorrow().ToDateTimeString() // 2020-08-06 14:14:15
Create a Carbon instance
// Create a Carbon instance from a given timestamp with second
carbon.CreateFromTimestamp(-1).ToDateTimeString() // 1970-01-01 07:59:59
carbon.CreateFromTimestamp(-1, carbon.Tokyo).ToDateTimeString() // 1970-01-01 08:59:59
carbon.CreateFromTimestamp(0).ToDateTimeString() // 1970-01-01 08:00:00
carbon.CreateFromTimestamp(0, carbon.Tokyo).ToDateTimeString() // 1970-01-01 09:00:00
carbon.CreateFromTimestamp(1596604455).ToDateTimeString() // 2020-08-05 13:14:15
carbon.CreateFromTimestamp(1596604455, carbon.Tokyo).ToDateTimeString() // 2020-08-05 14:14:15
// Create a Carbon instance from a given timestamp with millisecond
carbon.CreateFromTimestamp(1596604455000).ToDateTimeString() // 2020-08-05 13:14:15
carbon.CreateFromTimestamp(1596604455000, carbon.Tokyo).ToDateTimeString() // 2020-08-05 14:14:15
// Create a Carbon instance from a given timestamp with microsecond
carbon.CreateFromTimestamp(1596604455000000).ToDateTimeString() // 2020-08-05 13:14:15
carbon.CreateFromTimestamp(1596604455000000, carbon.Tokyo).ToDateTimeString() // 2020-08-05 14:14:15
// Create a Carbon instance from a given timestamp with nanosecond
carbon.CreateFromTimestamp(1596604455000000000).ToDateTimeString() // 2020-08-05 13:14:15
carbon.CreateFromTimestamp(1596604455000000000, carbon.Tokyo).ToDateTimeString() // 2020-08-05 14:14:15

// Create a Carbon instance from a given year, month, day, hour, minute and second
carbon.CreateFromDateTime(2020, 8, 5, 13, 14, 15).ToDateTimeString() // 2020-08-05 13:14:15
carbon.CreateFromDateTime(2020, 8, 5, 13, 14, 15, carbon.Tokyo).ToDateTimeString() // 2020-08-05 14:14:15
// Create a Carbon instance from a given year, month and day
carbon.CreateFromDate(2020, 8, 5).ToDateTimeString() // 2020-08-05 13:14:15
carbon.CreateFromDate(2020, 8, 5, carbon.Tokyo).ToDateTimeString() // 2020-08-05 14:14:15
// Create a Carbon instance from a given hour, minute and second
carbon.CreateFromTime(13, 14, 15).ToDateTimeString() // 2020-08-05 13:14:15
carbon.CreateFromTime(13, 14, 15, carbon.Tokyo).ToDateTimeString() // 2020-08-05 14:14:15
Parse a standard string as a Carbon instance
carbon.Parse("").ToDateTimeString() // empty string
carbon.Parse("0").ToDateTimeString() // empty string
carbon.Parse("0000-00-00 00:00:00").ToDateTimeString() // empty string
carbon.Parse("0000-00-00").ToDateTimeString() // empty string
carbon.Parse("2020-08-05 13:14:15").ToDateTimeString() // 2020-08-05 13:14:15
carbon.Parse("2020-08-05").ToDateTimeString() // 2020-08-05 00:00:00
carbon.Parse("20200805131415").ToDateTimeString() // 2020-08-05 13:14:15
carbon.Parse("20200805").ToDateTimeString() // 2020-08-05 00:00:00
carbon.Parse("2020-08-05T13:14:15+08:00").ToDateTimeString() // 2020-08-05 13:14:15
carbon.Parse("2020-08-05 13:14:15", carbon.Tokyo).ToDateTimeString() // 2020-08-05 14:14:15
Parse a string as a carbon instance by format
carbon.ParseByFormat("2020|08|05 13|14|15", "Y|m|d H|i|s").ToDateTimeString() // 2020-08-05 13:14:15
carbon.ParseByFormat("It is 2020-08-05 13:14:15", "\\I\\t \\i\\s Y-m-d H:i:s").ToDateTimeString() // 2020-08-05 13:14:15
carbon.ParseByFormat("今天是 2020年08月05日13时14分15秒", "今天是 Y年m月d日H时i分s秒").ToDateTimeString() // 2020-08-05 13:14:15
carbon.ParseByFormat("2020-08-05 13:14:15", "Y-m-d H:i:s", carbon.Tokyo).ToDateTimeString() // 2020-08-05 14:14:15
Parse a string as a carbon instance by layout
carbon.ParseByLayout("2020|08|05 13|14|15", "2006|01|02 15|04|05").ToDateTimeString() // 2020-08-05 13:14:15
carbon.ParseByLayout("It is 2020-08-05 13:14:15", "It is 2006-01-02 15:04:05").ToDateTimeString() // 2020-08-05 13:14:15
carbon.ParseByLayout("今天是 2020年08月05日13时14分15秒", "今天是 2006年01月02日15时04分05秒").ToDateTimeString() // 2020-08-05 13:14:15
carbon.ParseByLayout("2020-08-05 13:14:15", "2006-01-02 15:04:05", carbon.Tokyo).ToDateTimeString() // 2020-08-05 14:14:15
Convert between carbon and time.Time
// Convert Time.time into Carbon
carbon.Time2Carbon(time.Now())
// Convert Carbon into Time.time
carbon.Now().Carbon2Time()
Start and end
// Start of the century
carbon.Parse("2020-08-05 13:14:15").StartOfCentury().ToDateTimeString() // 2000-01-01 00:00:00
// End of the century
carbon.Parse("2020-08-05 13:14:15").EndOfCentury().ToDateTimeString() // 2999-12-31 23:59:59

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

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

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

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

// Start of the week
carbon.Parse("2020-08-05 13:14:15").StartOfWeek(time.Sunday).ToDateTimeString() // 2020-08-02 00:00:00
carbon.Parse("2020-08-05 13:14:15").StartOfWeek(time.Monday).ToDateTimeString() // 2020-08-03 00:00:00
// End of the week
carbon.Parse("2020-08-05 13:14:15").EndOfWeek(time.Sunday).ToDateTimeString() // 2020-08-08 23:59:59
carbon.Parse("2020-08-05 13:14:15").EndOfWeek(time.Monday).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().Format("Y-m-d H:i:s.u") // 2020-08-05 13:14:15.0
// End of the second
carbon.Parse("2020-08-05 13:14:15").EndOfSecond().Format("Y-m-d H:i:s.u") // 2020-08-05 13:14:15.999
Addition and subtraction
// Add three centuries
carbon.Parse("2020-02-29 13:14:15").AddCenturies(3).ToDateTimeString() // 2320-02-29 13:14:15
// Add three centuries without overflowing month
carbon.Parse("2020-02-29 13:14:15").AddCenturiesNoOverflow(3).ToDateTimeString() // 2320-02-29 13:14:15
// Add one century
carbon.Parse("2020-02-29 13:14:15").AddCentury().ToDateTimeString() // 2120-02-29 13:14:15
// Add one century without overflowing month
carbon.Parse("2020-02-29 13:14:15").AddCenturyNoOverflow().ToDateTimeString() // 2120-02-29 13:14:15
// Subtract three centuries
carbon.Parse("2020-02-29 13:14:15").SubCenturies(3).ToDateTimeString() // 1720-02-29 13:14:15
// Subtract three centuries without overflowing month
carbon.Parse("2020-02-29 13:14:15").SubCenturiesNoOverflow(3).ToDateTimeString() // 1720-02-29 13:14:15
// Subtract one century
carbon.Parse("2020-02-29 13:14:15").SubCentury().ToDateTimeString() // 1920-02-29 13:14:15
// Subtract one century without overflowing month
carbon.Parse("2020-02-29 13:14:15").SubCenturyNoOverflow().ToDateTimeString() // 1920-02-20 13:14:15

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

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

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

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

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

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

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

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

// Add three seconds
carbon.Parse("2020-08-05 13:14:15").AddSeconds(3).ToDateTimeString() // 2020-08-05 13:14:18
// Add two and a half seconds
carbon.Parse("2020-08-05 13:14:15").AddDuration("2.5s").ToDateTimeString() // 2020-08-05 13:14:17
// Add one second
carbon.Parse("2020-08-05 13:14:15").AddSecond().ToDateTimeString() // 2020-08-05 13:14:16
// Subtract three seconds
carbon.Parse("2020-08-05 13:14:15").SubSeconds(3).ToDateTimeString() // 2020-08-05 13:14:12
// Subtract two and a half seconds
carbon.Parse("2020-08-05 13:14:15").SubDuration("2.5s").ToDateTimeString() // 2020-08-05 13:14:12
// Subtract one second
carbon.Parse("2020-08-05 13:14:15").SubSecond().ToDateTimeString() // 2020-08-05 13:14:14
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").DiffInYearsWithAbs(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").DiffInMonthsWithAbs(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").DiffInWeeksWithAbs(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").DiffInDaysWithAbs(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").DiffInHoursWithAbs(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").DiffInMinutesWithAbs(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").DiffInSecondsWithAbs(carbon.Parse("2020-08-05 13:14:14")) // 1

// Difference in human friendly 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 human friendly readable format from now time
carbon.Parse("2020-08-05 13:14:15").DiffForHumans(carbon.Now()) // 1 year before
carbon.Parse("2019-08-05 13:14:15").DiffForHumans(carbon.Now()) // 2 years before
carbon.Parse("2018-08-05 13:14:15").DiffForHumans(carbon.Now()) // 1 year after
carbon.Parse("2022-08-05 13:14:15").DiffForHumans(carbon.Now()) // 2 years after
Comparison
// Whether is zero time
carbon.Parse("").IsZero() // true
carbon.Parse("0").IsZero() // true
carbon.Parse("0000-00-00 00:00:00").IsZero() // true
carbon.Parse("0000-00-00").IsZero() // true
carbon.Parse("00:00:00").IsZero() // true
carbon.Parse("2020-08-05 00:00:00").IsZero() // false
carbon.Parse("2020-08-05").IsZero() // false
carbon.Parse("2020-08-05").SetTimezone("xxx").IsZero() // false

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Output
// Output a timestamp with second, ToTimestamp() is short for ToTimestampWithSecond()
carbon.Parse("2020-08-05 13:14:15").ToTimestamp() // 1596604455
carbon.Parse("2020-08-05 13:14:15").ToTimestampWithSecond() // 1596604455
// Output a timestamp with millisecond
carbon.Parse("2020-08-05 13:14:15").ToTimestampWithMillisecond() // 1596604455000
// Output a timestamp with microsecond
carbon.Parse("2020-08-05 13:14:15").ToTimestampWithMicrosecond() // 1596604455000000
// Output a timestamp with nanosecond
carbon.Parse("2020-08-05 13:14:15").ToTimestampWithNanosecond() // 1596604455000000000

// Output a string in date and time format
carbon.Parse("2020-08-05 13:14:15").ToDateTimeString() // 2020-08-05 13:14:15
carbon.Parse("2020-08-05 13:14:15").ToDateTimeString(carbon.Tokyo) // 2020-08-05 14:14:15
// Output a string in short date and time format
carbon.Parse("2020-08-05 13:14:15").ToShortDateTimeString() // 20200805131415
carbon.Parse("2020-08-05 13:14:15").ToShortDateTimeString(carbon.Tokyo) // 20200805141415

// Output a in date format string
carbon.Parse("2020-08-05 13:14:15").ToDateString() // 2020-08-05
carbon.Parse("2020-08-05 13:14:15").ToDateString(carbon.Tokyo) // 2020-08-05
// Output a string in short date format
carbon.Parse("2020-08-05 13:14:15").ToShortDateString() // 20200805
carbon.Parse("2020-08-05 13:14:15").ToShortDateString(carbon.Tokyo) // 20200805

// Output a string in time format
carbon.Parse("2020-08-05 13:14:15").ToTimeString() // 13:14:15
carbon.Parse("2020-08-05 13:14:15").ToTimeString(carbon.Tokyo) // 14:14:15
// Output a string in short time format
carbon.Parse("2020-08-05 13:14:15").ToShortTimeString() // 131415
carbon.Parse("2020-08-05 13:14:15").ToShortTimeString(carbon.Tokyo) // 141415

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

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

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

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

// Output a string by layout, Layout() is short for ToLayoutString()
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
carbon.Parse("2020-08-05 13:14:15").Layout("2006-01-02 15:04:05", carbon.Tokyo) // 2020-08-05 14:14:15

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

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

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 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 with 0)
carbon.Parse("2020-08-05 13:14:15").Week() // 3
carbon.Parse("2020-08-05 13:14:15").Week() // 3
// 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").Millisecond() // 1596604455000
// Get current microsecond
carbon.Parse("2020-08-05 13:14:15").Microsecond() // 1596604455000000
// Get current nanosecond
carbon.Parse("2020-08-05 13:14:15").Nanosecond() // 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
Setter
// Set timezone
carbon.SetTimezone(carbon.PRC).Now().ToDateTimeString() // 2020-08-05 13:14:15
carbon.SetTimezone(carbon.Tokyo).Now().ToDateTimeString() // 2020-08-05 14:14:15
carbon.SetTimezone(carbon.Tokyo).Now().SetTimezone(carbon.PRC).ToDateTimeString() // 2020-08-05 12:14:15

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

// Set year
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 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
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
Lunar

Currently only 200 years from 1900 to 2100 are supported

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

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

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

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

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

// Whether is a year of the rat
carbon.Parse("2020-08-05 13:14:15", carbon.PRC).Lunar().IsRatYear() // true
// Whether is a year of the ox
carbon.Parse("2020-08-05 13:14:15", carbon.PRC).Lunar().IsOxYear() // false
// Whether is a year of the tiger
carbon.Parse("2020-08-05 13:14:15", carbon.PRC).Lunar().IsTigerYear() // false
// Whether is a year of the rabbit
carbon.Parse("2020-08-05 13:14:15", carbon.PRC).Lunar().IsRabbitYear() // false
// Whether is a year of the dragon
carbon.Parse("2020-08-05 13:14:15", carbon.PRC).Lunar().IsDragonYear() // false
// Whether is a year of the snake
carbon.Parse("2020-08-05 13:14:15", carbon.PRC).Lunar().IsSnakeYear() // false
// Whether is a year of the horse
carbon.Parse("2020-08-05 13:14:15", carbon.PRC).Lunar().IsHorseYear() // false
// Whether is a year of the goat
carbon.Parse("2020-08-05 13:14:15", carbon.PRC).Lunar().IsGoatYear() // false
// Whether is a year of the monkey
carbon.Parse("2020-08-05 13:14:15", carbon.PRC).Lunar().IsMonkeyYear() // false
// Whether is a year of the rooster
carbon.Parse("2020-08-05 13:14:15", carbon.PRC).Lunar().IsRoosterYear() // false
// Whether is a year of the dog
carbon.Parse("2020-08-05 13:14:15", carbon.PRC).Lunar().IsDogYear() // false
// Whether is a year of the dig
carbon.Parse("2020-08-05 13:14:15", carbon.PRC).Lunar().IsPigYear() // false
JSON handling
Define model
type Person struct {
    ID  int64  `json:"id"`
    Name string `json:"name"`
    Age int `json:"age"`
    Birthday carbon.ToDateTimeString `json:"birthday"`
    GraduatedAt carbon.ToDateString `json:"graduated_at"`
    CreatedAt carbon.ToTimeString `json:"created_at"`
    UpdatedAt carbon.ToTimestamp `json:"updated_at"`
    DateTime1 carbon.ToTimestampWithSecond `json:"date_time1"`
    DateTime2 carbon.ToTimestampWithMillisecond `json:"date_time2"`
    DateTime3 carbon.ToTimestampWithMicrosecond `json:"date_time3"`
    DateTime4 carbon.ToTimestampWithNanosecond `json:"date_time4"`
}
Instantiate model
person := Person {
	ID:          1,
	Name:        "gouguoyin",
	Age:         18,
	Birthday:    ToDateTimeString{Now().SubYears(18)},
	GraduatedAt: ToDateString{Parse("2020-08-05 13:14:15")},
	CreatedAt:   ToTimeString{Parse("2021-08-05 13:14:15")},
	UpdatedAt:   ToTimestamp{Parse("2022-08-05 13:14:15")},
	DateTime1:   ToTimestampWithSecond{Parse("2023-08-05 13:14:15")},
	DateTime2:   ToTimestampWithMillisecond{Parse("2024-08-05 13:14:15")},
	DateTime3:   ToTimestampWithMicrosecond{Parse("2025-08-05 13:14:15")},
	DateTime4:   ToTimestampWithNanosecond{Parse("2025-08-05 13:14:15")},
}
JSON encode
data, err := json.Marshal(&person)
if err != nil {
	t.Fatal(err)
}
fmt.Printf("%s",data)
// output
{
	"id":1,
	"name":"gouguoyin",
	"age":18,
	"birthday":"2003-07-16 16:22:02",
	"graduated_at":"2020-08-05",
	"created_at":"13:14:15",
	"updated_at":1659676455,
	"date_time1":1691212455,
	"date_time2":1722834855000,
	"date_time3":1754370855000000,
	"date_time4":1754370855000000000
}
JSON decode
str := `{
	"id":1,
	"name":"gouguoyin",
	"age":18,
	"birthday":"2003-07-16 16:22:02",
	"graduated_at":"2020-08-05",
	"created_at":"13:14:15",
	"updated_at":1659676455,
	"date_time1":1691212455,
	"date_time2":1722834855000,
	"date_time3":1754370855000000,
	"date_time4":1754370855000000000
}`
person := new(Person)
err := json.Unmarshal([]byte(str), &person)
if err != nil {
	t.Fatal(err)
}
fmt.Printf("%+v", *person)
// output
{ID:1 Name:gouguoyin Age:18 Birthday:2003-07-16 16:22:02 GraduatedAt:2020-08-05 00:00:00 CreatedAt:0000-01-01 13:14:15 UpdatedAt:2022-08-05 13:14:15 DTime1:2023-08-05 13:14:15 DateTime2:2024-08-05 13:14:15 DateTime3:2025-08-05 13:14:15 DateTime4:2025-08-05 13:14:15}
I18n

The following languages are supported

The following methods are supported

  • Constellation():get constellation name
  • Season():get season name
  • DiffForHumans():get the difference in human friendly readable format
  • ToMonthString():output a string in month format
  • ToShortMonthString():output a string in short month format
  • ToWeekString():output a string in week format
  • ToShortWeekString():output a string in short week format
Set locale
lang := NewLanguage()
if err := lang.SetLocale("zh-CN");err != nil {
    // Error handle...
    log.Fatal(err)
}

c := carbon.SetLanguage(lang)
c.Now().AddHours(1).DiffForHumans() // 1 小时后
c.Now().AddHours(1).ToMonthString() // 八月
c.Now().AddHours(1).ToShortMonthString() // 8月
c.Now().AddHours(1).ToWeekString() // 星期二
c.Now().AddHours(1).ToShortWeekString() // 周二
c.Now().AddHours(1).Constellation() // 狮子座
c.Now().AddHours(1).Season() // 夏季
Reset some resources(the rests still translate from the given locale)
lang := NewLanguage()

if err := lang.SetLocale("en");err != nil {
	// Error handle...
    log.Fatal(err)
}

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

c := carbon.SetLanguage(lang)
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 := NewLanguage()
resources := map[string]string {
    "months": "January|February|March|April|May|June|July|August|September|October|November|December",
    "months_short": "Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec",
    "weeks": "Sunday|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday",
    "weeks_short": "Sun|Mon|Tue|Wed|Thu|Fri|Sat",
    "seasons": "Spring|Summer|Autumn|Winter",
    "constellations": "Aries|Taurus|Gemini|Cancer|Leo|Virgo|Libra|Scorpio|Sagittarius|Capricornus|Aquarius|Pisce",
    "year":"1 yr|%d yrs",
    "month":"1 mo|%d mos",
    "week":"%dw",
    "day":"%dd",
    "hour":"%dh",
    "minute":"%dm",
    "second":"%ds",
    "now": "just now",
    "ago":"%s ago",
    "from_now":"in %s",
    "before":"%s before",
    "after":"%s after",
}
lang.SetResources(resources)

c := carbon.SetLanguage(lang)
c.Now().AddYears(1).DiffForHumans() // in 1 yr
c.Now().AddHours(1).DiffForHumans() // in 1h
c.Now().ToMonthString() // August
c.Now().ToShortMonthString() // Aug
c.Now().ToWeekString() // Tuesday
c.Now().ToShortWeekString() // Tue
c.Now().Constellation() // Leo
c.Now().Season() // Summer
Error handling

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

Scene one
c := carbon.SetTimezone(PRC).Parse("xxx")
if c.Error != nil {
    // Error handle...
    log.Fatal(c.Error)
}
fmt.Println(c.ToDateTimeString())
// Output
cannot parse "xxx" to carbon, please make sure the value is valid
Scene two
c := carbon.SetTimezone("xxx").Parse("2020-08-05")
if c.Error != nil {
    // Error handle...
    log.Fatal(c.Error)
}
fmt.Println(c.ToDateTimeString())
// Output
invalid timezone "xxx", please see the file "$GOROOT/lib/time/zoneinfo.zip" for all valid timezones
Scene three
c := carbon.SetTimezone("xxx").Parse("12345678")
if c.Error != nil {
    // Error handle...
    log.Fatal(c.Error)
}
fmt.Println(c.ToDateTimeString())
// Output
invalid timezone "xxx", please see the file "$GOROOT/lib/time/zoneinfo.zip" for all valid timezones
Appendix
sign desc length range example
d Day of the month, 2 digits with leading zeros 2 01-31 05
D A textual representation of a day, three letters 3 Mon-Sun Wed
j Day of the month without leading zeros - 1-31 5
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 A full textual representation of the day of the week - Monday-Sunday Wednesday
F A full textual representation of a month - January-December August
m Numeric representation of a month, with leading zeros 2 01-12 08
M A short textual representation of a month, three letters 3 Jan-Dec Aug
n Numeric representation of a month, without leading zeros - 1-12 8
y A two digit representation of a year 2 00-99 20
Y A full numeric representation of a year, 4 digits 4 0000-9999 2020
a Lowercase morning or afternoon sign 2 am/pm pm
A Uppercase morning or afternoon sign 2 AM/PM PM
g 12-hour format of an hour without leading zeros - 1-12 1
G 24-hour format of an hour without leading zeros - 0-23 15
h 12-hour format of an hour with leading zeros 2 00-11 03
H 24-hour format of an hour with leading zeros 2 00-23 15
i Minutes with leading zeros 2 01-59 14
s Seconds with leading zeros 2 01-59 15
c ISO 8601 date - - 2020-08-05T15:19:21+00:00
r RFC 2822 date - - Thu, 21 Dec 2020 16:01:07 +0200
O Difference to Greenwich time (GMT) without colon between hours and minutes - - +0200
P Difference to Greenwich time (GMT) with colon between hours and minutes - - +02:00
T Timezone abbreviation - - EST
W ISO8601 numeric representation of the week of the year - 1-52 42
N ISO8601 numeric representation of the day of the week 1 1-7 6
L Whether it's a leap year 1 0-1 1
U Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) 10 - 1611818268
u Millisecond 3 - 999
w Numeric representation of the day of the week 1 0-6 6
t Total days of the month 2 28-31 30
z Day of the year - 0-365 15
e Location - - America/New_York
Q Quarter 1 1-4 1
C Century - 0-99 21
References

Documentation

Overview

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

Index

Constants

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

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

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

时区常量

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

月份常量

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

星期常量

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秒
	MillisecondsPerSecond      = 1000    // 每秒1000毫秒
	MicrosecondsPerMillisecond = 1000    // 每毫秒1000微秒
	MicrosecondsPerSecond      = 1000000 // 每秒1000000微秒
)

数字常量

View Source
const (
	AnsicFormat         = time.ANSIC
	UnixDateFormat      = time.UnixDate
	RubyDateFormat      = time.RubyDate
	RFC822Format        = time.RFC822
	RFC822ZFormat       = time.RFC822Z
	RFC850Format        = time.RFC850
	RFC1123Format       = time.RFC1123
	RFC1123ZFormat      = time.RFC1123Z
	RssFormat           = time.RFC1123Z
	RFC2822Format       = time.RFC1123Z
	RFC3339Format       = time.RFC3339
	KitchenFormat       = time.Kitchen
	Iso8601Format       = "2006-01-02T15:04:05-07:00"
	CookieFormat        = "Monday, 02-Jan-2006 15:04:05 MST"
	RFC1036Format       = "Mon, 02 Jan 06 15:04:05 -0700"
	RFC7231Format       = "Mon, 02 Jan 2006 15:04:05 GMT"
	DayDateTimeFormat   = "Mon, Jan 2, 2006 3:04 PM"
	DateTimeFormat      = "2006-01-02 15:04:05"
	DateFormat          = "2006-01-02"
	TimeFormat          = "15:04:05"
	ShortDateTimeFormat = "20060102150405"
	ShortDateFormat     = "20060102"
	ShortTimeFormat     = "150405"
)

时间格式化常量

Variables

This section is empty.

Functions

This section is empty.

Types

type Carbon

type Carbon struct {
	Time  time.Time
	Loc   *time.Location
	Lang  *Language
	Error error
}

Carbon define Carbon structure 定义 Carbon 结构体

func CreateFromDate added in v1.2.0

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

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

func CreateFromDateTime added in v1.2.0

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

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

func CreateFromTime added in v1.2.0

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

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

func CreateFromTimestamp added in v1.2.0

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

CreateFromTimestamp create a Carbon instance from a given timestamp 从给定的时间戳创建 Carbon 实例

func NewCarbon added in v1.3.9

func NewCarbon() Carbon

NewCarbon return a new Carbon instance 初始化 Carbon 结构体

func Now added in v1.2.0

func Now(timezone ...string) Carbon

Now return a Carbon instance for now 当前

func Parse added in v1.2.0

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

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

func ParseByFormat added in v1.2.0

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

ParseByFormat parse a string as a Carbon instance by format 通过布局字符将字符串解析成 carbon 实例

func ParseByLayout added in v1.3.0

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

ParseByLayout parse a string as a Carbon instance by layout 将布局时间字符串解析成 Carbon 实例

func SetLanguage added in v1.3.4

func SetLanguage(lang *Language) Carbon

SetLanguage set language 设置语言对象

func SetLocale added in v1.3.4

func SetLocale(locale string) Carbon

SetLocale set locale 设置语言区域

func SetTimezone added in v1.2.2

func SetTimezone(name string) Carbon

SetTimezone set timezone 设置时区

func Time2Carbon added in v1.3.0

func Time2Carbon(tt time.Time) Carbon

Time2Carbon convert time.Time into Carbon 将 time.Time 转换成 Carbon

func Tomorrow added in v1.2.0

func Tomorrow(timezone ...string) Carbon

Tomorrow return a Carbon instance for tomorrow 明天

func Yesterday added in v1.2.0

func Yesterday(timezone ...string) Carbon

Yesterday return a Carbon instance for yesterday 昨天

func (Carbon) AddCenturies added in v1.2.6

func (c Carbon) AddCenturies(centuries int) Carbon

AddCenturies add some centuries N个世纪后

func (Carbon) AddCenturiesNoOverflow added in v1.3.0

func (c Carbon) AddCenturiesNoOverflow(centuries int) Carbon

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

func (Carbon) AddCentury added in v1.2.6

func (c Carbon) AddCentury() Carbon

AddCentury add one century 1个世纪后

func (Carbon) AddCenturyNoOverflow added in v1.3.0

func (c Carbon) AddCenturyNoOverflow() Carbon

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

func (Carbon) AddDay

func (c Carbon) AddDay() Carbon

AddDay add one day 1天后

func (Carbon) AddDays

func (c Carbon) AddDays(days int) Carbon

AddDays add some days N天后

func (Carbon) AddDecade added in v1.5.2

func (c Carbon) AddDecade() Carbon

AddDecade add one decade 1个年代后

func (Carbon) AddDecadeNoOverflow added in v1.5.2

func (c Carbon) AddDecadeNoOverflow() Carbon

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

func (Carbon) AddDecades added in v1.5.2

func (c Carbon) AddDecades(decades int) Carbon

AddDecades add some decades N个年代后

func (Carbon) AddDecadesNoOverflow added in v1.5.2

func (c Carbon) AddDecadesNoOverflow(decades int) Carbon

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

func (Carbon) AddDuration added in v1.2.4

func (c Carbon) AddDuration(duration string) Carbon

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

func (Carbon) AddHour

func (c Carbon) AddHour() Carbon

AddHour add one hour 1小时后

func (Carbon) AddHours

func (c Carbon) AddHours(hours int) Carbon

AddHours add some hours N小时后

func (Carbon) AddMinute

func (c Carbon) AddMinute() Carbon

AddMinute add one minute 1分钟后

func (Carbon) AddMinutes

func (c Carbon) AddMinutes(minutes int) Carbon

AddMinutes add some minutes N分钟后

func (Carbon) AddMonth

func (c Carbon) AddMonth() Carbon

AddMonth add one month 1个月后

func (Carbon) AddMonthNoOverflow added in v1.3.0

func (c Carbon) AddMonthNoOverflow() Carbon

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

func (Carbon) AddMonths

func (c Carbon) AddMonths(months int) Carbon

AddMonths add some months N个月后

func (Carbon) AddMonthsNoOverflow added in v1.3.0

func (c Carbon) AddMonthsNoOverflow(months int) Carbon

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

func (Carbon) AddQuarter added in v1.2.3

func (c Carbon) AddQuarter() Carbon

AddQuarter add one quarter 1个季度后

func (Carbon) AddQuarterNoOverflow added in v1.3.0

func (c Carbon) AddQuarterNoOverflow() Carbon

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

func (Carbon) AddQuarters added in v1.2.3

func (c Carbon) AddQuarters(quarters int) Carbon

AddQuarters add some quarters N个季度后

func (Carbon) AddQuartersNoOverflow added in v1.3.0

func (c Carbon) AddQuartersNoOverflow(quarters int) Carbon

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

func (Carbon) AddSecond

func (c Carbon) AddSecond() Carbon

AddSecond add one second 1秒钟后

func (Carbon) AddSeconds

func (c Carbon) AddSeconds(seconds int) Carbon

AddSeconds add some seconds N秒钟后

func (Carbon) AddWeek

func (c Carbon) AddWeek() Carbon

AddWeek add one week 1周后

func (Carbon) AddWeeks

func (c Carbon) AddWeeks(weeks int) Carbon

AddWeeks add some weeks N周后

func (Carbon) AddYear

func (c Carbon) AddYear() Carbon

AddYear add one year 1年后

func (Carbon) AddYearNoOverflow added in v1.3.0

func (c Carbon) AddYearNoOverflow() Carbon

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

func (Carbon) AddYears

func (c Carbon) AddYears(years int) Carbon

AddYears add some years N年后

func (Carbon) AddYearsNoOverflow added in v1.3.0

func (c Carbon) AddYearsNoOverflow(years int) Carbon

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

func (Carbon) Age added in v1.2.1

func (c Carbon) Age() int

Age get age 获取年龄

func (Carbon) Between added in v1.2.4

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

Between whether between two Carbon instances, excluded the start and end Carbon instance 是否在两个时间之间(不包括这两个时间)

func (Carbon) BetweenIncludedBoth added in v1.2.4

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

BetweenIncludedBoth whether between two Carbon instances, included the start and end Carbon instance 是否在两个时间之间(包括这两个时间)

func (Carbon) BetweenIncludedEnd added in v1.4.5

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

BetweenIncludedEnd whether between two Carbon instances, included the end Carbon instance 是否在两个时间之间(包括结束时间)

func (Carbon) BetweenIncludedStart added in v1.4.5

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

BetweenIncludedStart whether between two Carbon instances, included the start Carbon instance 是否在两个时间之间(包括开始时间)

func (Carbon) Carbon2Time added in v1.3.0

func (c Carbon) Carbon2Time() time.Time

Carbon2Time convert Carbon into time.Time 将 Carbon 转换成 time.Time

func (Carbon) Century added in v1.3.4

func (c Carbon) Century() int

Century get current century 获取当前世纪

func (Carbon) Compare added in v1.2.4

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

Compare comparison by a operator 时间比较

func (Carbon) Constellation added in v1.3.4

func (c Carbon) Constellation() string

Constellation get constellation name, i18n is supported 获取星座,支持i18n

func (Carbon) CreateFromDate

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

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

func (Carbon) CreateFromDateTime

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

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

func (Carbon) CreateFromTime

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

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

func (Carbon) CreateFromTimestamp

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

CreateFromTimestamp create a Carbon instance from a given timestamp, second, millisecond, microsecond and nanosecond are supported 从给定的时间戳创建 Carbon 实例,支持秒、毫秒、微秒和纳秒

func (Carbon) Day added in v1.2.1

func (c Carbon) Day() int

Day get current day 获取当前日

func (Carbon) DayOfMonth added in v1.2.0

func (c Carbon) DayOfMonth() int

DayOfMonth get day of month 获取本月的第几天

func (Carbon) DayOfWeek added in v1.2.0

func (c Carbon) DayOfWeek() int

DayOfWeek get day of week 获取本周的第几天

func (Carbon) DayOfYear added in v1.2.0

func (c Carbon) DayOfYear() int

DayOfYear get day of year 获取本年的第几天

func (Carbon) DaysInMonth added in v1.2.0

func (c Carbon) DaysInMonth() int

DaysInMonth get days in month 获取本月的总天数

func (Carbon) DaysInYear added in v1.2.0

func (c Carbon) DaysInYear() int

DaysInYear get days in year 获取本年的总天数

func (Carbon) Decade added in v1.4.2

func (c Carbon) Decade() int

Decade get current decade 获取当前年代

func (Carbon) DiffForHumans added in v1.3.1

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

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

func (Carbon) DiffInDays added in v1.2.2

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

DiffInDays get the difference in days 相差多少天

func (Carbon) DiffInDaysWithAbs added in v1.2.4

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

DiffInDaysWithAbs get the difference in days with absolute value 相差多少天(绝对值)

func (Carbon) DiffInHours added in v1.2.2

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

DiffInHours get the difference in hours 相差多少小时

func (Carbon) DiffInHoursWithAbs added in v1.2.4

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

DiffInHoursWithAbs get the difference in hours with absolute value 相差多少小时(绝对值)

func (Carbon) DiffInMinutes added in v1.2.2

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

DiffInMinutes get the difference in minutes 相差多少分钟

func (Carbon) DiffInMinutesWithAbs added in v1.2.4

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

DiffInMinutesWithAbs get the difference in minutes with absolute value 相差多少分钟(绝对值)

func (Carbon) DiffInMonths added in v1.3.1

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

DiffInMonths get the difference in months 相差多少月

func (Carbon) DiffInMonthsWithAbs added in v1.3.1

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

DiffInMonthsWithAbs get the difference in months with absolute value 相差多少月(绝对值)

func (Carbon) DiffInSeconds added in v1.2.2

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

DiffInSeconds get the difference in seconds 相差多少秒

func (Carbon) DiffInSecondsWithAbs added in v1.2.4

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

DiffInSecondsWithAbs get the difference in seconds with absolute value 相差多少秒(绝对值)

func (Carbon) DiffInWeeks added in v1.2.2

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

DiffInWeeks get the difference in weeks 相差多少周

func (Carbon) DiffInWeeksWithAbs added in v1.2.4

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

DiffInWeeksWithAbs get the difference in weeks with absolute value 相差多少周(绝对值)

func (Carbon) DiffInYears added in v1.3.1

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

DiffInYears get the difference in years 相差多少年

func (Carbon) DiffInYearsWithAbs added in v1.3.1

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

DiffInYearsWithAbs get the difference in years with absolute value 相差多少年(绝对值)

func (Carbon) EndOfCentury added in v1.4.0

func (c Carbon) EndOfCentury() Carbon

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

func (Carbon) EndOfDay

func (c Carbon) EndOfDay() Carbon

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

func (Carbon) EndOfDecade added in v1.4.2

func (c Carbon) EndOfDecade() Carbon

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

func (Carbon) EndOfHour added in v1.2.1

func (c Carbon) EndOfHour() Carbon

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

func (Carbon) EndOfMinute added in v1.2.1

func (c Carbon) EndOfMinute() Carbon

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

func (Carbon) EndOfMonth

func (c Carbon) EndOfMonth() Carbon

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

func (Carbon) EndOfQuarter added in v1.4.0

func (c Carbon) EndOfQuarter() Carbon

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

func (Carbon) EndOfSeason added in v1.4.2

func (c Carbon) EndOfSeason() Carbon

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

func (Carbon) EndOfSecond added in v1.3.4

func (c Carbon) EndOfSecond() Carbon

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

func (Carbon) EndOfWeek added in v1.2.1

func (c Carbon) EndOfWeek(weekStartDay time.Weekday) Carbon

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

func (Carbon) EndOfYear

func (c Carbon) EndOfYear() Carbon

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

func (Carbon) Eq added in v1.2.4

func (c Carbon) Eq(t Carbon) bool

Eq whether equal 是否等于

func (Carbon) Format

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

Format Output a string by format, it is short for ToFormatString 输出指定格式的时间字符串, 是 ToFormatString 的简写

func (Carbon) Gt added in v1.2.4

func (c Carbon) Gt(t Carbon) bool

Gt whether greater than 是否大于

func (Carbon) Gte added in v1.2.4

func (c Carbon) Gte(t Carbon) bool

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

func (Carbon) Hour added in v1.2.1

func (c Carbon) Hour() int

Hour get current hour 获取当前小时

func (Carbon) IsApril

func (c Carbon) IsApril() bool

IsApril whether is April 是否是四月

func (Carbon) IsAquarius added in v1.3.4

func (c Carbon) IsAquarius() bool

IsAquarius whether is Aquarius 是否是水瓶座

func (Carbon) IsAries added in v1.3.4

func (c Carbon) IsAries() bool

IsAries whether is Aries 是否是白羊座

func (Carbon) IsAugust

func (c Carbon) IsAugust() bool

IsAugust whether is August 是否是八月

func (Carbon) IsAutumn added in v1.4.2

func (c Carbon) IsAutumn() bool

IsAutumn whether is autumn 是否是秋季

func (Carbon) IsCancer added in v1.3.4

func (c Carbon) IsCancer() bool

IsCancer whether is Cancer 是否是巨蟹座

func (Carbon) IsCapricorn added in v1.3.4

func (c Carbon) IsCapricorn() bool

IsCapricorn whether is Capricorn 是否是摩羯座

func (Carbon) IsDecember

func (c Carbon) IsDecember() bool

IsDecember whether is December 是否是十二月

func (Carbon) IsFebruary

func (c Carbon) IsFebruary() bool

IsFebruary whether is February 是否是二月

func (Carbon) IsFriday

func (c Carbon) IsFriday() bool

IsFriday whether is Friday 是否是周五

func (Carbon) IsFuture added in v1.2.0

func (c Carbon) IsFuture() bool

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

func (Carbon) IsGemini added in v1.3.4

func (c Carbon) IsGemini() bool

IsGemini whether is Gemini 是否是双子座

func (Carbon) IsInvalid added in v1.4.4

func (c Carbon) IsInvalid() bool

IsInvalid whether is invalid time 是否是无效的

func (Carbon) IsJanuary

func (c Carbon) IsJanuary() bool

IsJanuary whether is January 是否是一月

func (Carbon) IsJuly

func (c Carbon) IsJuly() bool

IsJuly whether is July 是否是七月

func (Carbon) IsJune

func (c Carbon) IsJune() bool

IsJune whether is June 是否是六月

func (Carbon) IsLeapYear

func (c Carbon) IsLeapYear() bool

IsLeapYear whether is a leap year 是否是闰年

func (Carbon) IsLeo added in v1.3.4

func (c Carbon) IsLeo() bool

IsLeo whether is Leo 是否是狮子座

func (Carbon) IsLibra added in v1.3.4

func (c Carbon) IsLibra() bool

IsLibra whether is Libra 是否是天秤座

func (Carbon) IsLongYear added in v1.2.2

func (c Carbon) IsLongYear() bool

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

func (Carbon) IsMarch

func (c Carbon) IsMarch() bool

IsMarch whether is March 是否是三月

func (Carbon) IsMay

func (c Carbon) IsMay() bool

IsMay whether is May 是否是五月

func (Carbon) IsMonday

func (c Carbon) IsMonday() bool

IsMonday whether is Monday 是否是周一

func (Carbon) IsNovember

func (c Carbon) IsNovember() bool

IsNovember whether is November 是否是十一月

func (Carbon) IsNow added in v1.2.1

func (c Carbon) IsNow() bool

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

func (Carbon) IsOctober

func (c Carbon) IsOctober() bool

IsOctober whether is October 是否是十月

func (Carbon) IsPast added in v1.2.0

func (c Carbon) IsPast() bool

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

func (Carbon) IsPisces added in v1.3.4

func (c Carbon) IsPisces() bool

IsPisces whether is Pisces 是否是双鱼座

func (Carbon) IsSagittarius added in v1.3.4

func (c Carbon) IsSagittarius() bool

IsSagittarius whether is Sagittarius 是否是射手座

func (Carbon) IsSaturday

func (c Carbon) IsSaturday() bool

IsSaturday whether is Saturday 是否是周六

func (Carbon) IsScorpio added in v1.3.4

func (c Carbon) IsScorpio() bool

IsScorpio whether is Scorpio 是否是天蝎座

func (Carbon) IsSeptember

func (c Carbon) IsSeptember() bool

IsSeptember whether is September 是否是九月

func (Carbon) IsSpring added in v1.4.2

func (c Carbon) IsSpring() bool

IsSpring whether is spring 是否是春季

func (Carbon) IsSummer added in v1.4.2

func (c Carbon) IsSummer() bool

IsSummer whether is summer 是否是夏季

func (Carbon) IsSunday

func (c Carbon) IsSunday() bool

IsSunday whether is Sunday 是否是周日

func (Carbon) IsTaurus added in v1.3.4

func (c Carbon) IsTaurus() bool

IsTaurus whether is Taurus 是否是金牛座

func (Carbon) IsThursday

func (c Carbon) IsThursday() bool

IsThursday whether is Thursday 是否是周四

func (Carbon) IsToday

func (c Carbon) IsToday() bool

IsToday whether is today 是否是今天

func (Carbon) IsTomorrow

func (c Carbon) IsTomorrow() bool

IsTomorrow whether is tomorrow 是否是明天

func (Carbon) IsTuesday

func (c Carbon) IsTuesday() bool

IsTuesday whether is Tuesday 是否是周二

func (Carbon) IsVirgo added in v1.3.4

func (c Carbon) IsVirgo() bool

IsVirgo whether is Virgo 是否是处女座

func (Carbon) IsWednesday

func (c Carbon) IsWednesday() bool

IsWednesday whether is Wednesday 是否是周三

func (Carbon) IsWeekday added in v1.2.0

func (c Carbon) IsWeekday() bool

IsWeekday whether is weekday 是否是工作日

func (Carbon) IsWeekend added in v1.2.0

func (c Carbon) IsWeekend() bool

IsWeekend whether is weekend 是否是周末

func (Carbon) IsWinter added in v1.4.2

func (c Carbon) IsWinter() bool

IsWinter whether is winter 是否是冬季

func (Carbon) IsYesterday

func (c Carbon) IsYesterday() bool

IsYesterday whether is yesterday 是否是昨天

func (Carbon) IsZero added in v1.2.0

func (c Carbon) IsZero() bool

IsZero whether is zero time 是否是零值

func (Carbon) Layout added in v1.4.4

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

Layout Output a string by layout, it is short for ToLayoutString 输出指定布局的时间字符串, 是 ToLayoutString 的简写

func (Carbon) Locale added in v1.3.1

func (c Carbon) Locale() string

Locale get locale name 获取语言区域

func (Carbon) Location added in v1.4.4

func (c Carbon) Location() string

Location get location name 获取位置

func (Carbon) Lt added in v1.2.4

func (c Carbon) Lt(t Carbon) bool

Lt whether less than 是否小于

func (Carbon) Lte added in v1.2.4

func (c Carbon) Lte(t Carbon) bool

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

func (Carbon) Lunar added in v1.4.1

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

Lunar convert the gregorian calendar into the lunar calendar 将公历转为农历

func (Carbon) Microsecond added in v1.2.3

func (c Carbon) Microsecond() int

Microsecond get current microsecond 获取当前微秒数,6位数字

func (Carbon) Millisecond added in v1.2.3

func (c Carbon) Millisecond() int

Millisecond get current millisecond 获取当前毫秒数,3位数字

func (Carbon) Minute added in v1.2.1

func (c Carbon) Minute() int

Minute get current minute 获取当前分钟数

func (Carbon) Month added in v1.2.1

func (c Carbon) Month() int

Month get current month 获取当前月

func (Carbon) MonthOfYear added in v1.2.0

func (c Carbon) MonthOfYear() int

MonthOfYear get month of year 获取本年的第几月

func (Carbon) Nanosecond added in v1.2.3

func (c Carbon) Nanosecond() int

Nanosecond get current nanosecond 获取当前纳秒数,9位数字

func (Carbon) Ne added in v1.2.4

func (c Carbon) Ne(t Carbon) bool

Ne whether not equal 是否不等于

func (Carbon) Now

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

Now return a Carbon instance for now 当前

func (Carbon) Offset added in v1.4.4

func (c Carbon) Offset() int

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

func (Carbon) Parse

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

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

func (Carbon) ParseByFormat

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

ParseByFormat parse a string as a Carbon instance by format 通过格式化字符将字符串解析成 carbon 实例

func (Carbon) ParseByLayout added in v1.3.0

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

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

func (Carbon) Quarter added in v1.2.3

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

Quarter get current quarter 获取当前季度

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

func (c Carbon) Season() string

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

func (Carbon) Second added in v1.2.1

func (c Carbon) Second() int

Second get current second 获取当前秒数

func (Carbon) SetDay added in v1.2.2

func (c Carbon) SetDay(day int) Carbon

SetDay set day 设置日

func (Carbon) SetHour added in v1.2.2

func (c Carbon) SetHour(hour int) Carbon

SetHour set hour 设置时

func (Carbon) SetLanguage added in v1.3.4

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

SetLanguage set language 设置语言对象

func (Carbon) SetLocale added in v1.3.1

func (c Carbon) SetLocale(locale string) Carbon

SetLocale set locale 设置语言区域

func (Carbon) SetMicrosecond added in v1.3.7

func (c Carbon) SetMicrosecond(microsecond int) Carbon

SetMicrosecond set microsecond 设置微秒

func (Carbon) SetMillisecond added in v1.3.7

func (c Carbon) SetMillisecond(millisecond int) Carbon

SetMillisecond set millisecond 设置毫秒

func (Carbon) SetMinute added in v1.2.2

func (c Carbon) SetMinute(minute int) Carbon

SetMinute set minute 设置分

func (Carbon) SetMonth added in v1.2.2

func (c Carbon) SetMonth(month int) Carbon

SetMonth set month 设置月

func (Carbon) SetMonthNoOverflow added in v1.5.2

func (c Carbon) SetMonthNoOverflow(month int) Carbon

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

func (Carbon) SetNanosecond added in v1.3.7

func (c Carbon) SetNanosecond(nanosecond int) Carbon

SetNanosecond set nanosecond 设置纳秒

func (Carbon) SetSecond added in v1.2.2

func (c Carbon) SetSecond(second int) Carbon

SetSecond set second 设置秒

func (Carbon) SetTimezone added in v1.2.2

func (c Carbon) SetTimezone(name string) Carbon

SetTimezone set timezone 设置时区

func (Carbon) SetYear added in v1.2.2

func (c Carbon) SetYear(year int) Carbon

SetYear set year 设置年

func (Carbon) SetYearNoOverflow added in v1.5.2

func (c Carbon) SetYearNoOverflow(year int) Carbon

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

func (Carbon) StartOfCentury added in v1.4.0

func (c Carbon) StartOfCentury() Carbon

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

func (Carbon) StartOfDay

func (c Carbon) StartOfDay() Carbon

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

func (Carbon) StartOfDecade added in v1.4.2

func (c Carbon) StartOfDecade() Carbon

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

func (Carbon) StartOfHour added in v1.2.2

func (c Carbon) StartOfHour() Carbon

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

func (Carbon) StartOfMinute added in v1.2.2

func (c Carbon) StartOfMinute() Carbon

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

func (Carbon) StartOfMonth

func (c Carbon) StartOfMonth() Carbon

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

func (Carbon) StartOfQuarter added in v1.4.0

func (c Carbon) StartOfQuarter() Carbon

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

func (Carbon) StartOfSeason added in v1.4.2

func (c Carbon) StartOfSeason() Carbon

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

func (Carbon) StartOfSecond added in v1.3.4

func (c Carbon) StartOfSecond() Carbon

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

func (Carbon) StartOfWeek added in v1.2.2

func (c Carbon) StartOfWeek(weekStartDay time.Weekday) Carbon

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

func (Carbon) StartOfYear

func (c Carbon) StartOfYear() Carbon

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

func (Carbon) String added in v1.3.7

func (c Carbon) String() string

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

func (Carbon) SubCenturies added in v1.2.6

func (c Carbon) SubCenturies(centuries int) Carbon

SubCenturies subtraction some centuries N个世纪前

func (Carbon) SubCenturiesNoOverflow added in v1.3.0

func (c Carbon) SubCenturiesNoOverflow(centuries int) Carbon

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

func (Carbon) SubCentury added in v1.2.6

func (c Carbon) SubCentury() Carbon

SubCentury subtraction one century 1个世纪前

func (Carbon) SubCenturyNoOverflow added in v1.3.0

func (c Carbon) SubCenturyNoOverflow() Carbon

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

func (Carbon) SubDay

func (c Carbon) SubDay() Carbon

SubDay subtraction one day 1天前

func (Carbon) SubDays

func (c Carbon) SubDays(days int) Carbon

SubDays subtraction some days N天前

func (Carbon) SubDecade added in v1.5.2

func (c Carbon) SubDecade() Carbon

SubDecade subtraction one decade 1个年代后

func (Carbon) SubDecadeNoOverflow added in v1.5.2

func (c Carbon) SubDecadeNoOverflow() Carbon

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

func (Carbon) SubDecades added in v1.5.2

func (c Carbon) SubDecades(decades int) Carbon

SubDecades subtraction some decades N个年代后

func (Carbon) SubDecadesNoOverflow added in v1.5.2

func (c Carbon) SubDecadesNoOverflow(decades int) Carbon

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

func (Carbon) SubDuration added in v1.2.4

func (c Carbon) SubDuration(duration string) Carbon

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

func (Carbon) SubHour

func (c Carbon) SubHour() Carbon

SubHour subtraction one hour 1小时前

func (Carbon) SubHours

func (c Carbon) SubHours(hours int) Carbon

SubHours subtraction some hours N小时前

func (Carbon) SubMinute

func (c Carbon) SubMinute() Carbon

SubMinute subtraction one minute 1分钟前

func (Carbon) SubMinutes

func (c Carbon) SubMinutes(minutes int) Carbon

SubMinutes subtraction some minutes N分钟前

func (Carbon) SubMonth

func (c Carbon) SubMonth() Carbon

SubMonth subtraction one month 1个月前

func (Carbon) SubMonthNoOverflow added in v1.3.0

func (c Carbon) SubMonthNoOverflow() Carbon

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

func (Carbon) SubMonths

func (c Carbon) SubMonths(months int) Carbon

SubMonths subtraction some months N个月前

func (Carbon) SubMonthsNoOverflow added in v1.3.0

func (c Carbon) SubMonthsNoOverflow(months int) Carbon

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

func (Carbon) SubQuarter added in v1.2.3

func (c Carbon) SubQuarter() Carbon

SubQuarter subtraction one quarter 1个季度前

func (Carbon) SubQuarterNoOverflow added in v1.3.0

func (c Carbon) SubQuarterNoOverflow() Carbon

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

func (Carbon) SubQuarters added in v1.2.3

func (c Carbon) SubQuarters(quarters int) Carbon

SubQuarters subtraction some quarters N个季度前

func (Carbon) SubQuartersNoOverflow added in v1.3.0

func (c Carbon) SubQuartersNoOverflow(quarters int) Carbon

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

func (Carbon) SubSecond

func (c Carbon) SubSecond() Carbon

SubSecond subtraction one second 1秒钟前

func (Carbon) SubSeconds

func (c Carbon) SubSeconds(seconds int) Carbon

SubSeconds subtraction some seconds N秒钟前

func (Carbon) SubWeek

func (c Carbon) SubWeek() Carbon

SubWeek subtraction one week 1周前

func (Carbon) SubWeeks

func (c Carbon) SubWeeks(weeks int) Carbon

SubWeeks subtraction some weeks N周前

func (Carbon) SubYear

func (c Carbon) SubYear() Carbon

SubYear subtraction one year 1年前

func (Carbon) SubYearNoOverflow added in v1.3.0

func (c Carbon) SubYearNoOverflow() Carbon

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

func (Carbon) SubYears

func (c Carbon) SubYears(years int) Carbon

SubYears subtraction some years N年前

func (Carbon) SubYearsNoOverflow added in v1.3.0

func (c Carbon) SubYearsNoOverflow(years int) Carbon

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

func (Carbon) Timezone

func (c Carbon) Timezone() string

Timezone get timezone name 获取时区

func (Carbon) ToAnsicString added in v1.2.0

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

ToAnsicString output a string in ANSIC format 输出 ANSIC 格式字符串

func (Carbon) ToAtomString added in v1.2.0

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

ToAtomString output a string in ATOM format 输出 ATOM 格式字符串

func (Carbon) ToCookieString added in v1.2.0

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

ToCookieString output a string in COOKIE format 输出 COOKIE 格式字符串

func (Carbon) ToDateString

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

ToDateString output a string in date format 输出日期字符串

func (Carbon) ToDateTimeString

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

ToDateTimeString output a string in date and time format 输出日期时间字符串

func (Carbon) ToDayDateTimeString added in v1.2.0

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

ToDayDateTimeString output a string in day, date and time format 输出天数日期时间字符串

func (Carbon) ToFormatString added in v1.2.0

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

ToFormatString output a string by format 输出指定格式的时间字符串

func (Carbon) ToIso8601String added in v1.4.4

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

ToIso8601String output a string in ISO8601 format 输出 ISO8601 格式字符串

func (Carbon) ToKitchenString added in v1.2.0

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

ToKitchenString output a string in KITCHEN format 输出 KITCHEN 格式字符串

func (Carbon) ToLayoutString added in v1.4.4

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

ToLayoutString output a string by layout 输出指定布局的时间字符串

func (Carbon) ToMonthString added in v1.3.4

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

ToMonthString output a string in month format, i18n is supported 输出完整月份字符串,支持i18n

func (Carbon) ToRfc1036String added in v1.3.0

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

ToRfc1036String output a string in RFC1036 format 输出 RFC1036 格式字符串

func (Carbon) ToRfc1123String added in v1.3.0

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

ToRfc1123String output a string in RFC1123 format 输出 RFC1123 格式字符串

func (Carbon) ToRfc1123zString added in v1.4.5

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

ToRfc1123zString output a string in RFC1123z format 输出 RFC1123z 格式字符串

func (Carbon) ToRfc2822String added in v1.3.0

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

ToRfc2822String output a string in RFC2822 format 输出 RFC2822 格式字符串

func (Carbon) ToRfc3339String added in v1.3.0

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

ToRfc3339String output a string in RFC3339 format 输出 RFC3339 格式字符串

func (Carbon) ToRfc7231String added in v1.3.0

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

ToRfc7231String output a string in RFC7231 format 输出 RFC7231 格式字符串

func (Carbon) ToRfc822String added in v1.3.0

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

ToRfc822String output a string in RFC822 format 输出 RFC822 格式字符串

func (Carbon) ToRfc822zString added in v1.3.0

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

ToRfc822zString output a string in RFC822Z format 输出 RFC822Z 格式字符串

func (Carbon) ToRfc850String added in v1.3.0

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

ToRfc850String output a string in RFC850 format 输出 RFC850 格式字符串

func (Carbon) ToRssString added in v1.2.0

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

ToRssString output a string in RSS format 输出 RSS 格式字符串

func (Carbon) ToRubyDateString added in v1.2.0

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

ToRubyDateString output a string in ruby date format 输出 RubyDate 格式字符串

func (Carbon) ToShortDateString added in v1.4.4

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

ToShortDateString output a string in short date format 输出简写日期字符串

func (Carbon) ToShortDateTimeString added in v1.4.4

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

ToShortDateTimeString output a string in short date and time format 输出简写日期时间字符串

func (Carbon) ToShortMonthString added in v1.3.4

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

ToShortMonthString output a string in short month format, i18n is supported 输出缩写月份字符串,支持i18n

func (Carbon) ToShortTimeString added in v1.4.4

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

ToShortTimeString output a string in short time format 输出简写时间字符串

func (Carbon) ToShortWeekString added in v1.3.4

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

ToShortWeekString output a string in short week format, i18n is supported 输出缩写星期字符串,支持i18n

func (Carbon) ToString added in v1.2.0

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

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

func (Carbon) ToTimeString

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

ToTimeString output a string in time format 输出时间字符串

func (Carbon) ToTimestamp

func (c Carbon) ToTimestamp() int64

ToTimestamp output a timestamp with second, it is short for ToTimestampWithSecond 输出秒级时间戳, 是 ToTimestampWithSecond 的简写

func (Carbon) ToTimestampWithMicrosecond added in v1.2.3

func (c Carbon) ToTimestampWithMicrosecond() int64

ToTimestampWithMicrosecond output a timestamp with microsecond 输出微秒级时间戳

func (Carbon) ToTimestampWithMillisecond added in v1.2.3

func (c Carbon) ToTimestampWithMillisecond() int64

ToTimestampWithMillisecond output a timestamp with millisecond 输出毫秒级时间戳

func (Carbon) ToTimestampWithNanosecond added in v1.2.3

func (c Carbon) ToTimestampWithNanosecond() int64

ToTimestampWithNanosecond output a timestamp with nanosecond 输出纳秒级时间戳

func (Carbon) ToTimestampWithSecond added in v1.2.3

func (c Carbon) ToTimestampWithSecond() int64

ToTimestampWithSecond output a timestamp with second 输出秒级时间戳

func (Carbon) ToUnixDateString added in v1.2.0

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

ToUnixDateString output a string in unix date format 输出 UnixDate 格式字符串

func (Carbon) ToW3cString added in v1.2.0

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

ToW3cString output a string in W3C format 输出 W3C 格式字符串

func (Carbon) ToWeekString added in v1.3.4

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

ToWeekString output a string in week format, i18n is supported 输出完整星期字符串,支持i18n

func (Carbon) Tomorrow

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

Tomorrow return a Carbon instance for tomorrow 明天

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

func (c Carbon) Week() int

Week get current week, start from 0 获取当前周(从0开始)

func (Carbon) WeekOfMonth added in v1.2.0

func (c Carbon) WeekOfMonth() int

WeekOfMonth get week of month 获取本月的第几周

func (Carbon) WeekOfYear added in v1.2.0

func (c Carbon) WeekOfYear() int

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

func (Carbon) Year added in v1.2.1

func (c Carbon) Year() int

Year get current year 获取当前年

func (Carbon) Yesterday

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

Yesterday return a Carbon instance for yesterday 昨天

type Language added in v1.3.1

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

Language 定义 Language 结构体 define Language structure

func NewLanguage added in v1.3.1

func NewLanguage() *Language

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

func (*Language) SetLocale added in v1.3.1

func (l *Language) SetLocale(locale string) error

SetLocale set language locale 设置区域

func (*Language) SetResources added in v1.3.4

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

SetResources set language resources 设置资源

type ToDateString

type ToDateString struct {
	Carbon
}

ToDateString define ToDateTimeString structure

func (ToDateString) MarshalJSON

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

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*ToDateString) UnmarshalJSON added in v1.4.3

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

UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.

type ToDateTimeString

type ToDateTimeString struct {
	Carbon
}

ToDateTimeString define ToDateTimeString structure

func (ToDateTimeString) MarshalJSON

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

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*ToDateTimeString) UnmarshalJSON added in v1.4.3

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

UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.

type ToTimeString

type ToTimeString struct {
	Carbon
}

ToTimeString define ToTimeString structure

func (ToTimeString) MarshalJSON

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

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*ToTimeString) UnmarshalJSON added in v1.4.3

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

UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.

type ToTimestamp

type ToTimestamp struct {
	Carbon
}

ToTimestamp define ToTimestamp structure

func (ToTimestamp) MarshalJSON

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

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*ToTimestamp) UnmarshalJSON added in v1.4.3

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

UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.

type ToTimestampWithMicrosecond added in v1.2.4

type ToTimestampWithMicrosecond struct {
	Carbon
}

ToTimestampWithMicrosecond define ToTimestampWithMicrosecond structure

func (ToTimestampWithMicrosecond) MarshalJSON added in v1.2.4

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

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*ToTimestampWithMicrosecond) UnmarshalJSON added in v1.4.3

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

UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.

type ToTimestampWithMillisecond added in v1.2.4

type ToTimestampWithMillisecond struct {
	Carbon
}

ToTimestampWithMillisecond define ToTimestampWithMillisecond structure

func (ToTimestampWithMillisecond) MarshalJSON added in v1.2.4

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

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*ToTimestampWithMillisecond) UnmarshalJSON added in v1.4.3

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

UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.

type ToTimestampWithNanosecond added in v1.2.4

type ToTimestampWithNanosecond struct {
	Carbon
}

ToTimestampWithNanosecond define ToTimestampWithNanosecond structure

func (ToTimestampWithNanosecond) MarshalJSON added in v1.2.4

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

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*ToTimestampWithNanosecond) UnmarshalJSON added in v1.4.3

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

UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.

type ToTimestampWithSecond added in v1.2.4

type ToTimestampWithSecond struct {
	Carbon
}

ToTimestampWithSecond define ToTimestampWithSecond structure

func (ToTimestampWithSecond) MarshalJSON added in v1.2.4

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

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*ToTimestampWithSecond) UnmarshalJSON added in v1.4.3

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

UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.

Directories

Path Synopsis
Package lang is a part of the package carbon
Package lang is a part of the package carbon

Jump to

Keyboard shortcuts

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