carbon

package module
v1.0.16 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2021 License: MIT Imports: 7 Imported by: 0

README

Carbon

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

English | 简体中文 | 日本語

Introduction

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

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

github.com/golang-module/carbon

gitee.com/go-package/carbon

Installation
// 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 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 timestamp with second of today
carbon.Now().Timestamp() // 1596604455
carbon.Now().TimestampWithSecond() // 1596604455
// Return timestamp with millisecond of today
carbon.Now().TimestampWithMillisecond() // 1596604455000
// Return timestamp with microsecond of today
carbon.Now().TimestampWithMicrosecond() // 1596604455000000
// Return timestamp with nanosecond of today
carbon.Now().TimestampWithNanosecond() // 1596604455000000000

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

// Return datetime of tomorrow
fmt.Sprintf("%s", carbon.Tomorrow()) // 2020-08-06 13:14:15
carbon.Tomorrow().ToDateTimeString() // 2020-08-06 13:14:15
// Return date of tomorrow
carbon.Tomorrow().ToDateString() // 2020-08-06
// Return time of tomorrow
carbon.Tomorrow().ToTimeString() // 13:14:15
// Return datetime of tomorrow on a given day
carbon.Parse("2021-01-28 13:14:15").Tomorrow().ToDateTimeString() // 2021-01-29 13:14:15
// Return datetime of tomorrow in a given timezone
carbon.Tomorrow(Carbon.NewYork).ToDateTimeString() // 2020-08-06 14:14:15
carbon.SetTimezone(Carbon.NewYork).Tomorrow().ToDateTimeString() // 2020-08-06 14:14:15
// Return timestamp with second of tomorrow
carbon.Tomorrow().Timestamp() // 1596690855
carbon.Tomorrow().TimestampWithSecond() // 1596690855
// Return timestamp with millisecond of tomorrow
carbon.Tomorrow().TimestampWithMillisecond() // 1596690855000
// Return timestamp with microsecond of tomorrow
carbon.Tomorrow().TimestampWithMicrosecond() // 1596690855000000
// Return timestamp with nanosecond of tomorrow
carbon.Tomorrow().TimestampWithNanosecond() // 1596690855000000000
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().ToDateTimeString() // 2020-08-02 00:00:00
carbon.Parse("2020-08-05 13:14:15").SetWeekStartsAt(carbon.Sunday).StartOfWeek().ToDateTimeString() // 2020-08-02 00:00:00
carbon.Parse("2020-08-05 13:14:15").SetWeekStartsAt(carbon.Monday).StartOfWeek().ToDateTimeString() // 2020-08-03 00:00:00
// End of the week
carbon.Parse("2020-08-05 13:14:15").EndOfWeek().ToDateTimeString() // 2020-08-08 23:59:59
carbon.Parse("2020-08-05 13:14:15").SetWeekStartsAt(carbon.Sunday).EndOfWeek().ToDateTimeString() // 2020-08-08 23:59:59
carbon.Parse("2020-08-05 13:14:15").SetWeekStartsAt(carbon.Monday).EndOfWeek().ToDateTimeString() // 2020-08-09 23:59:59

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

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

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

// Start of the second
carbon.Parse("2020-08-05 13:14:15").StartOfSecond().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 see https://en.wikipedia.org/wiki/ISO_8601#Week_dates

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

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

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

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

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

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

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

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

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

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

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

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

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

// Get current 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-02 13:14:15").Week() // 0
carbon.Parse("2020-08-02").SetWeekStartsAt(carbon.Sunday).Week() // 0
carbon.Parse("2020-08-02").SetWeekStartsAt(carbon.Monday).Week() // 6
// Get current day
carbon.Parse("2020-08-05 13:14:15").Day() // 5
// Get current hour
carbon.Parse("2020-08-05 13:14:15").Hour() // 13
// Get current minute
carbon.Parse("2020-08-05 13:14:15").Minute() // 14
// Get current second
carbon.Parse("2020-08-05 13:14:15").Second() // 15
// Get current millisecond
carbon.Parse("2020-08-05 13:14:15").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 timestamp with second, Timestamp() is short for TimestampWithSecond()
carbon.Parse("2020-08-05 13:14:15").Timestamp() // 1596604455
carbon.Parse("2020-08-05 13:14:15").TimestampWithSecond() // 1596604455
// Get timestamp with millisecond
carbon.Parse("2020-08-05 13:14:15").TimestampWithMillisecond() // 1596604455000
// Get timestamp with microsecond
carbon.Parse("2020-08-05 13:14:15").TimestampWithMicrosecond() // 1596604455000000
// Get timestamp with nanosecond
carbon.Parse("2020-08-05 13:14:15").TimestampWithNanosecond() // 1596604455000000000

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

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

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

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

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

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

// Get current age
carbon.Parse("2002-01-01 13:14:15").Age() // 17
carbon.Parse("2002-12-31 13:14:15").Age() // 18
Output
// Output a string in date and time format
carbon.Parse("2020-08-05 13:14:15").ToDateTimeString() // 2020-08-05 13:14:15
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

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

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

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

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

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

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

Currently only 200 years from 1900 to 2100 are supported

// Get Chinese Lunar year of animal
carbon.Parse("2020-08-05 13:14:15", 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.DateTime `json:"birthday"`
    GraduatedAt carbon.Date `json:"graduated_at"`
    CreatedAt carbon.Time `json:"created_at"`
    UpdatedAt carbon.Timestamp `json:"updated_at"`
    DateTime1 carbon.TimestampWithSecond `json:"date_time1"`
    DateTime2 carbon.TimestampWithMillisecond `json:"date_time2"`
    DateTime3 carbon.TimestampWithMicrosecond `json:"date_time3"`
    DateTime4 carbon.TimestampWithNanosecond `json:"date_time4"`
}
Instantiate model
person := Person {
    ID:          1,
    Name:        "gouguoyin",
    Age:         18,
    Birthday:    carbon.DateTime{carbon.Now().SubYears(18)},
    GraduatedAt: carbon.Date{carbon.Parse("2020-08-05 13:14:15")},
    CreatedAt:   carbon.Time{carbon.Parse("2021-08-05 13:14:15")},
    UpdatedAt:   carbon.Timestamp{carbon.Parse("2022-08-05 13:14:15")},
    DateTime1:   carbon.TimestampWithSecond{carbon.Parse("2023-08-05 13:14:15")},
    DateTime2:   carbon.TimestampWithMillisecond{carbon.Parse("2024-08-05 13:14:15")},
    DateTime3:   carbon.TimestampWithMicrosecond{carbon.Parse("2025-08-05 13:14:15")},
    DateTime4:   carbon.TimestampWithNanosecond{carbon.Parse("2025-08-05 13:14:15")},
}
JSON encode
data, err := json.Marshal(&person)
if err != nil {
    // Error handle...
    log.Fatal(err)
}
fmt.Printf("%s", data)
// output
{
    "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
jsonString := `{
	"id": 1,
	"name": "gouguoyin",
	"age": 18,
	"birthday": "2003-07-16 16:22:02",
	"graduated_at": "2020-08-05",
	"updated_at": 1659676455,
	"date_time1": 1691212455,
	"date_time2": 1722834855000,
	"date_time3": 1754370855000000,
	"date_time4": 1754370855000000000
}`
person := new(Person)
err := json.Unmarshal([]byte(jsonString), &person)
if err != nil {
    // Error handle...
    log.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 UpdatedAt:2022-08-05 13:14:15 DateTime1:2023-08-05 13:14:15 DateTime2:2024-08-05 13:14:15 DateTime3:2025-08-05 13:14:15 DateTime4:2025-08-05 13:14:15}
I18n

The following languages are supported

The following methods are supported

  • Constellation():get constellation name
  • Season():get season name
  • DiffForHumans():get the difference in human 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",
	"short_months": "jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec",
	"weeks": "sunday|monday|tuesday|wednesday|thursday|friday|saturday",
	"short_weeks": "sun|mon|tue|wed|thu|fri|sat",
	"seasons": "spring|summer|autumn|winter",
	"constellations": "aries|taurus|gemini|cancer|leo|virgo|libra|scorpio|sagittarius|capricornus|aquarius|pisce",
	"year": "1 yr|%d yrs",
	"month": "1 mo|%d mos",
	"week": "%dw",
	"day": "%dd",
	"hour": "%dh",
	"minute": "%dm",
	"second": "%ds",
	"now": "just now",
	"ago": "%s ago",
	"from_now": "in %s",
	"before": "%s before",
	"after": "%s after",
}
lang.SetResources(resources)

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

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

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

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"         // 罗马
)

timezones constant 时区常量

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

months constant 月份常量

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

weeks constant 星期常量

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

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

numbers constant 数字常量

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

formats constant 时间格式化常量

Variables

This section is empty.

Functions

This section is empty.

Types

type Carbon

type Carbon struct {
	Time time.Time

	Error error
	// contains filtered or unexported fields
}

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

func CreateFromDate

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

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

func CreateFromDateTime

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

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

func CreateFromTime

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

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

func CreateFromTimestamp

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

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

func NewCarbon

func NewCarbon() Carbon

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

func Now

func Now(timezone ...string) Carbon

Now returns a Carbon instance for now. 当前

func Parse

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

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

func ParseByFormat

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

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

func ParseByLayout

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

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

func SetLanguage

func SetLanguage(lang *Language) Carbon

SetLanguage sets language. 设置语言对象

func SetLocale

func SetLocale(locale string) Carbon

SetLocale sets locale. 设置语言区域

func SetTimezone

func SetTimezone(name string) Carbon

SetTimezone sets timezone. 设置时区

func Time2Carbon

func Time2Carbon(tt time.Time) Carbon

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

func Tomorrow

func Tomorrow(timezone ...string) Carbon

Tomorrow returns a Carbon instance for tomorrow. 明天

func Yesterday

func Yesterday(timezone ...string) Carbon

Yesterday returns a Carbon instance for yesterday. 昨天

func (Carbon) AddCenturies

func (c Carbon) AddCenturies(centuries int) Carbon

AddCenturies adds some centuries. N个世纪后

func (Carbon) AddCenturiesNoOverflow

func (c Carbon) AddCenturiesNoOverflow(centuries int) Carbon

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

func (Carbon) AddCentury

func (c Carbon) AddCentury() Carbon

AddCentury adds one century. 1个世纪后

func (Carbon) AddCenturyNoOverflow

func (c Carbon) AddCenturyNoOverflow() Carbon

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

func (Carbon) AddDay

func (c Carbon) AddDay() Carbon

AddDay adds one day. 1天后

func (Carbon) AddDays

func (c Carbon) AddDays(days int) Carbon

AddDays adds some days. N天后

func (Carbon) AddDecade

func (c Carbon) AddDecade() Carbon

AddDecade adds one decade. 1个年代后

func (Carbon) AddDecadeNoOverflow

func (c Carbon) AddDecadeNoOverflow() Carbon

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

func (Carbon) AddDecades

func (c Carbon) AddDecades(decades int) Carbon

AddDecades adds some decades. N个年代后

func (Carbon) AddDecadesNoOverflow

func (c Carbon) AddDecadesNoOverflow(decades int) Carbon

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

func (Carbon) AddDuration

func (c Carbon) AddDuration(duration string) Carbon

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

func (Carbon) AddHour

func (c Carbon) AddHour() Carbon

AddHour adds one hour. 1小时后

func (Carbon) AddHours

func (c Carbon) AddHours(hours int) Carbon

AddHours adds some hours. N小时后

func (Carbon) AddMinute

func (c Carbon) AddMinute() Carbon

AddMinute adds one minute. 1分钟后

func (Carbon) AddMinutes

func (c Carbon) AddMinutes(minutes int) Carbon

AddMinutes adds some minutes. N分钟后

func (Carbon) AddMonth

func (c Carbon) AddMonth() Carbon

AddMonth adds one month. 1个月后

func (Carbon) AddMonthNoOverflow

func (c Carbon) AddMonthNoOverflow() Carbon

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

func (Carbon) AddMonths

func (c Carbon) AddMonths(months int) Carbon

AddMonths adds some months. N个月后

func (Carbon) AddMonthsNoOverflow

func (c Carbon) AddMonthsNoOverflow(months int) Carbon

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

func (Carbon) AddQuarter

func (c Carbon) AddQuarter() Carbon

AddQuarter adds one quarter 1个季度后

func (Carbon) AddQuarterNoOverflow

func (c Carbon) AddQuarterNoOverflow() Carbon

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

func (Carbon) AddQuarters

func (c Carbon) AddQuarters(quarters int) Carbon

AddQuarters adds some quarters N个季度后

func (Carbon) AddQuartersNoOverflow

func (c Carbon) AddQuartersNoOverflow(quarters int) Carbon

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

func (Carbon) AddSecond

func (c Carbon) AddSecond() Carbon

AddSecond adds one second. 1秒钟后

func (Carbon) AddSeconds

func (c Carbon) AddSeconds(seconds int) Carbon

AddSeconds adds some seconds. N秒钟后

func (Carbon) AddWeek

func (c Carbon) AddWeek() Carbon

AddWeek adds one week. 1周后

func (Carbon) AddWeeks

func (c Carbon) AddWeeks(weeks int) Carbon

AddWeeks adds some weeks. N周后

func (Carbon) AddYear

func (c Carbon) AddYear() Carbon

AddYear adds one year. 1年后

func (Carbon) AddYearNoOverflow

func (c Carbon) AddYearNoOverflow() Carbon

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

func (Carbon) AddYears

func (c Carbon) AddYears(years int) Carbon

AddYears adds some years. N年后

func (Carbon) AddYearsNoOverflow

func (c Carbon) AddYearsNoOverflow(years int) Carbon

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

func (Carbon) Age

func (c Carbon) Age() int

Age gets age. 获取年龄

func (Carbon) Between

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

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

func (Carbon) BetweenIncludedBoth

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

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

func (Carbon) BetweenIncludedEnd

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

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

func (Carbon) BetweenIncludedStart

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

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

func (Carbon) Carbon2Time

func (c Carbon) Carbon2Time() time.Time

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

func (Carbon) Century

func (c Carbon) Century() int

Century gets current century. 获取当前世纪

func (Carbon) Compare

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

Compare comparison by a operator. 时间比较

func (Carbon) Constellation

func (c Carbon) Constellation() string

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

func (Carbon) CreateFromDate

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

CreateFromDate creates 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 creates 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 creates a Carbon instance from a given time. 从给定的时分秒创建 Carbon 实例

func (Carbon) CreateFromTimestamp

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

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

func (Carbon) Day

func (c Carbon) Day() int

Day gets current day. 获取当前日

func (Carbon) DayOfMonth

func (c Carbon) DayOfMonth() int

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

func (Carbon) DayOfWeek

func (c Carbon) DayOfWeek() int

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

func (Carbon) DayOfYear

func (c Carbon) DayOfYear() int

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

func (Carbon) DaysInMonth

func (c Carbon) DaysInMonth() int

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

func (Carbon) DaysInYear

func (c Carbon) DaysInYear() int

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

func (Carbon) Decade

func (c Carbon) Decade() int

Decade gets current decade. 获取当前年代

func (Carbon) DiffForHumans

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

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

func (Carbon) DiffInDays

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

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

func (Carbon) DiffInDaysWithAbs

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

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

func (Carbon) DiffInHours

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

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

func (Carbon) DiffInHoursWithAbs

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

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

func (Carbon) DiffInMinutes

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

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

func (Carbon) DiffInMinutesWithAbs

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

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

func (Carbon) DiffInMonths

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

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

func (Carbon) DiffInMonthsWithAbs

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

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

func (Carbon) DiffInSeconds

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

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

func (Carbon) DiffInSecondsWithAbs

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

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

func (Carbon) DiffInWeeks

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

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

func (Carbon) DiffInWeeksWithAbs

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

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

func (Carbon) DiffInYears

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

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

func (Carbon) DiffInYearsWithAbs

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

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

func (Carbon) EndOfCentury

func (c Carbon) EndOfCentury() Carbon

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

func (Carbon) EndOfDay

func (c Carbon) EndOfDay() Carbon

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

func (Carbon) EndOfDecade

func (c Carbon) EndOfDecade() Carbon

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

func (Carbon) EndOfHour

func (c Carbon) EndOfHour() Carbon

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

func (Carbon) EndOfMinute

func (c Carbon) EndOfMinute() Carbon

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

func (Carbon) EndOfMonth

func (c Carbon) EndOfMonth() Carbon

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

func (Carbon) EndOfQuarter

func (c Carbon) EndOfQuarter() Carbon

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

func (Carbon) EndOfSeason

func (c Carbon) EndOfSeason() Carbon

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

func (Carbon) EndOfSecond

func (c Carbon) EndOfSecond() Carbon

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

func (Carbon) EndOfWeek

func (c Carbon) EndOfWeek() Carbon

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

func (Carbon) EndOfYear

func (c Carbon) EndOfYear() Carbon

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

func (Carbon) Eq

func (c Carbon) Eq(t Carbon) bool

Eq whether equal. 是否等于

func (Carbon) Format

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

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

func (Carbon) Gt

func (c Carbon) Gt(t Carbon) bool

Gt whether greater than. 是否大于

func (Carbon) Gte

func (c Carbon) Gte(t Carbon) bool

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

func (Carbon) Hour

func (c Carbon) Hour() int

Hour gets current hour. 获取当前小时

func (Carbon) IsApril

func (c Carbon) IsApril() bool

IsApril whether is April. 是否是四月

func (Carbon) IsAquarius

func (c Carbon) IsAquarius() bool

IsAquarius whether is Aquarius. 是否是水瓶座

func (Carbon) IsAries

func (c Carbon) IsAries() bool

IsAries whether is Aries. 是否是白羊座

func (Carbon) IsAugust

func (c Carbon) IsAugust() bool

IsAugust whether is August. 是否是八月

func (Carbon) IsAutumn

func (c Carbon) IsAutumn() bool

IsAutumn whether is autumn. 是否是秋季

func (Carbon) IsCancer

func (c Carbon) IsCancer() bool

IsCancer whether is Cancer. 是否是巨蟹座

func (Carbon) IsCapricorn

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

func (c Carbon) IsFuture() bool

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

func (Carbon) IsGemini

func (c Carbon) IsGemini() bool

IsGemini whether is Gemini. 是否是双子座

func (Carbon) IsInvalid

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

func (c Carbon) IsLeo() bool

IsLeo whether is Leo. 是否是狮子座

func (Carbon) IsLibra

func (c Carbon) IsLibra() bool

IsLibra whether is Libra. 是否是天秤座

func (Carbon) IsLongYear

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

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

func (c Carbon) IsPast() bool

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

func (Carbon) IsPisces

func (c Carbon) IsPisces() bool

IsPisces whether is Pisces. 是否是双鱼座

func (Carbon) IsSagittarius

func (c Carbon) IsSagittarius() bool

IsSagittarius whether is Sagittarius. 是否是射手座

func (Carbon) IsSaturday

func (c Carbon) IsSaturday() bool

IsSaturday whether is Saturday. 是否是周六

func (Carbon) IsScorpio

func (c Carbon) IsScorpio() bool

IsScorpio whether is Scorpio. 是否是天蝎座

func (Carbon) IsSeptember

func (c Carbon) IsSeptember() bool

IsSeptember whether is September. 是否是九月

func (Carbon) IsSpring

func (c Carbon) IsSpring() bool

IsSpring whether is spring. 是否是春季

func (Carbon) IsSummer

func (c Carbon) IsSummer() bool

IsSummer whether is summer. 是否是夏季

func (Carbon) IsSunday

func (c Carbon) IsSunday() bool

IsSunday whether is Sunday. 是否是周日

func (Carbon) IsTaurus

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

func (c Carbon) IsVirgo() bool

IsVirgo whether is Virgo. 是否是处女座

func (Carbon) IsWednesday

func (c Carbon) IsWednesday() bool

IsWednesday whether is Wednesday. 是否是周三

func (Carbon) IsWeekday

func (c Carbon) IsWeekday() bool

IsWeekday whether is weekday. 是否是工作日

func (Carbon) IsWeekend

func (c Carbon) IsWeekend() bool

IsWeekend whether is weekend. 是否是周末

func (Carbon) IsWinter

func (c Carbon) IsWinter() bool

IsWinter whether is winter. 是否是冬季

func (Carbon) IsYesterday

func (c Carbon) IsYesterday() bool

IsYesterday whether is yesterday. 是否是昨天

func (Carbon) IsZero

func (c Carbon) IsZero() bool

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

func (Carbon) Layout

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

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

func (Carbon) Locale

func (c Carbon) Locale() string

Locale gets locale name. 获取语言区域

func (Carbon) Location

func (c Carbon) Location() string

Location gets location name. 获取位置

func (Carbon) Lt

func (c Carbon) Lt(t Carbon) bool

Lt whether less than. 是否小于

func (Carbon) Lte

func (c Carbon) Lte(t Carbon) bool

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

func (Carbon) Lunar

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

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

func (Carbon) Microsecond

func (c Carbon) Microsecond() int

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

func (Carbon) Millisecond

func (c Carbon) Millisecond() int

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

func (Carbon) Minute

func (c Carbon) Minute() int

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

func (Carbon) Month

func (c Carbon) Month() int

Month gets current month. 获取当前月

func (Carbon) MonthOfYear

func (c Carbon) MonthOfYear() int

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

func (Carbon) Nanosecond

func (c Carbon) Nanosecond() int

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

func (Carbon) Ne

func (c Carbon) Ne(t Carbon) bool

Ne whether not equal. 是否不等于

func (Carbon) Now

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

Now returns a Carbon instance for now. 当前

func (Carbon) Offset

func (c Carbon) Offset() int

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

func (Carbon) Parse

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

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

func (Carbon) ParseByFormat

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

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

func (Carbon) ParseByLayout

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

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

func (Carbon) Quarter

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

Quarter gets 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

func (c Carbon) Season() string

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

func (Carbon) Second

func (c Carbon) Second() int

Second gets current second. 获取当前秒数

func (Carbon) SetDay

func (c Carbon) SetDay(day int) Carbon

SetDay sets day. 设置日期

func (Carbon) SetHour

func (c Carbon) SetHour(hour int) Carbon

SetHour sets hour. 设置小时

func (Carbon) SetLanguage

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

SetLanguage sets language. 设置语言对象

func (Carbon) SetLocale

func (c Carbon) SetLocale(locale string) Carbon

SetLocale sets locale. 设置语言区域

func (Carbon) SetMicrosecond

func (c Carbon) SetMicrosecond(microsecond int) Carbon

SetMicrosecond sets microsecond. 设置微秒

func (Carbon) SetMillisecond

func (c Carbon) SetMillisecond(millisecond int) Carbon

SetMillisecond sets millisecond. 设置毫秒

func (Carbon) SetMinute

func (c Carbon) SetMinute(minute int) Carbon

SetMinute sets minute. 设置分钟

func (Carbon) SetMonth

func (c Carbon) SetMonth(month int) Carbon

SetMonth sets month. 设置月份

func (Carbon) SetMonthNoOverflow

func (c Carbon) SetMonthNoOverflow(month int) Carbon

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

func (Carbon) SetNanosecond

func (c Carbon) SetNanosecond(nanosecond int) Carbon

SetNanosecond sets nanosecond. 设置纳秒

func (Carbon) SetSecond

func (c Carbon) SetSecond(second int) Carbon

SetSecond sets second. 设置秒数

func (Carbon) SetTimezone

func (c Carbon) SetTimezone(name string) Carbon

SetTimezone sets timezone. 设置时区

func (Carbon) SetWeekStartsAt

func (c Carbon) SetWeekStartsAt(day string) Carbon

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

func (Carbon) SetYear

func (c Carbon) SetYear(year int) Carbon

SetYear sets year. 设置年份

func (Carbon) SetYearNoOverflow

func (c Carbon) SetYearNoOverflow(year int) Carbon

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

func (Carbon) StartOfCentury

func (c Carbon) StartOfCentury() Carbon

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

func (Carbon) StartOfDay

func (c Carbon) StartOfDay() Carbon

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

func (Carbon) StartOfDecade

func (c Carbon) StartOfDecade() Carbon

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

func (Carbon) StartOfHour

func (c Carbon) StartOfHour() Carbon

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

func (Carbon) StartOfMinute

func (c Carbon) StartOfMinute() Carbon

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

func (Carbon) StartOfMonth

func (c Carbon) StartOfMonth() Carbon

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

func (Carbon) StartOfQuarter

func (c Carbon) StartOfQuarter() Carbon

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

func (Carbon) StartOfSeason

func (c Carbon) StartOfSeason() Carbon

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

func (Carbon) StartOfSecond

func (c Carbon) StartOfSecond() Carbon

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

func (Carbon) StartOfWeek

func (c Carbon) StartOfWeek() Carbon

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

func (Carbon) StartOfYear

func (c Carbon) StartOfYear() Carbon

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

func (Carbon) String

func (c Carbon) String() string

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

func (Carbon) SubCenturies

func (c Carbon) SubCenturies(centuries int) Carbon

SubCenturies subtracts some centuries. N个世纪前

func (Carbon) SubCenturiesNoOverflow

func (c Carbon) SubCenturiesNoOverflow(centuries int) Carbon

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

func (Carbon) SubCentury

func (c Carbon) SubCentury() Carbon

SubCentury subtracts one century. 1个世纪前

func (Carbon) SubCenturyNoOverflow

func (c Carbon) SubCenturyNoOverflow() Carbon

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

func (Carbon) SubDay

func (c Carbon) SubDay() Carbon

SubDay subtracts one day. 1天前

func (Carbon) SubDays

func (c Carbon) SubDays(days int) Carbon

SubDays subtracts some days. N天前

func (Carbon) SubDecade

func (c Carbon) SubDecade() Carbon

SubDecade subtracts one decade. 1个年代后

func (Carbon) SubDecadeNoOverflow

func (c Carbon) SubDecadeNoOverflow() Carbon

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

func (Carbon) SubDecades

func (c Carbon) SubDecades(decades int) Carbon

SubDecades subtracts some decades. N个年代后

func (Carbon) SubDecadesNoOverflow

func (c Carbon) SubDecadesNoOverflow(decades int) Carbon

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

func (Carbon) SubDuration

func (c Carbon) SubDuration(duration string) Carbon

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

func (Carbon) SubHour

func (c Carbon) SubHour() Carbon

SubHour subtracts one hour. 1小时前

func (Carbon) SubHours

func (c Carbon) SubHours(hours int) Carbon

SubHours subtracts some hours. N小时前

func (Carbon) SubMinute

func (c Carbon) SubMinute() Carbon

SubMinute subtracts one minute. 1分钟前

func (Carbon) SubMinutes

func (c Carbon) SubMinutes(minutes int) Carbon

SubMinutes subtracts some minutes. N分钟前

func (Carbon) SubMonth

func (c Carbon) SubMonth() Carbon

SubMonth subtracts one month. 1个月前

func (Carbon) SubMonthNoOverflow

func (c Carbon) SubMonthNoOverflow() Carbon

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

func (Carbon) SubMonths

func (c Carbon) SubMonths(months int) Carbon

SubMonths subtracts some months. N个月前

func (Carbon) SubMonthsNoOverflow

func (c Carbon) SubMonthsNoOverflow(months int) Carbon

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

func (Carbon) SubQuarter

func (c Carbon) SubQuarter() Carbon

SubQuarter subtracts one quarter. 1个季度前

func (Carbon) SubQuarterNoOverflow

func (c Carbon) SubQuarterNoOverflow() Carbon

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

func (Carbon) SubQuarters

func (c Carbon) SubQuarters(quarters int) Carbon

SubQuarters subtracts some quarters. N个季度前

func (Carbon) SubQuartersNoOverflow

func (c Carbon) SubQuartersNoOverflow(quarters int) Carbon

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

func (Carbon) SubSecond

func (c Carbon) SubSecond() Carbon

SubSecond subtracts one second. 1秒钟前

func (Carbon) SubSeconds

func (c Carbon) SubSeconds(seconds int) Carbon

SubSeconds subtracts some seconds. N秒钟前

func (Carbon) SubWeek

func (c Carbon) SubWeek() Carbon

SubWeek subtracts one week. 1周前

func (Carbon) SubWeeks

func (c Carbon) SubWeeks(weeks int) Carbon

SubWeeks subtracts some weeks. N周前

func (Carbon) SubYear

func (c Carbon) SubYear() Carbon

SubYear subtracts one year. 1年前

func (Carbon) SubYearNoOverflow

func (c Carbon) SubYearNoOverflow() Carbon

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

func (Carbon) SubYears

func (c Carbon) SubYears(years int) Carbon

SubYears subtracts some years. N年前

func (Carbon) SubYearsNoOverflow

func (c Carbon) SubYearsNoOverflow(years int) Carbon

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

func (Carbon) Timestamp

func (c Carbon) Timestamp() int64

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

func (Carbon) TimestampWithMicrosecond

func (c Carbon) TimestampWithMicrosecond() int64

TimestampWithMicrosecond gets timestamp with microsecond. 获取微秒级时间戳

func (Carbon) TimestampWithMillisecond

func (c Carbon) TimestampWithMillisecond() int64

TimestampWithMillisecond gets timestamp with millisecond. 获取毫秒级时间戳

func (Carbon) TimestampWithNanosecond

func (c Carbon) TimestampWithNanosecond() int64

TimestampWithNanosecond gets timestamp with nanosecond. 获取纳秒级时间戳

func (Carbon) TimestampWithSecond

func (c Carbon) TimestampWithSecond() int64

TimestampWithSecond gets timestamp with second. 输出秒级时间戳

func (Carbon) Timezone

func (c Carbon) Timezone() string

Timezone gets timezone name. 获取时区

func (Carbon) ToAnsicString

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

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

func (Carbon) ToAtomString

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

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

func (Carbon) ToCookieString

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

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

func (Carbon) ToDateString

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

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

func (Carbon) ToDateTimeString

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

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

func (Carbon) ToDayDateTimeString

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

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

func (Carbon) ToFormatString

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

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

func (Carbon) ToIso8601String

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

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

func (Carbon) ToKitchenString

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

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

func (Carbon) ToLayoutString

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

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

func (Carbon) ToMonthString

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

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

func (Carbon) ToRfc1036String

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

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

func (Carbon) ToRfc1123String

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

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

func (Carbon) ToRfc1123zString

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

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

func (Carbon) ToRfc2822String

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

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

func (Carbon) ToRfc3339String

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

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

func (Carbon) ToRfc7231String

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

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

func (Carbon) ToRfc822String

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

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

func (Carbon) ToRfc822zString

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

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

func (Carbon) ToRfc850String

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

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

func (Carbon) ToRssString

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

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

func (Carbon) ToRubyDateString

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

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

func (Carbon) ToShortDateString

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

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

func (Carbon) ToShortDateTimeString

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

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

func (Carbon) ToShortMonthString

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

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

func (Carbon) ToShortTimeString

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

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

func (Carbon) ToShortWeekString

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

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

func (Carbon) ToString

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

ToString outputs 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 outputs a string in time format. 输出时间字符串

func (Carbon) ToTimestamp

func (c Carbon) ToTimestamp() int64

ToTimestamp outputs a timestamp with second(will be removed from v2.0, only keep Timestamp). 输出秒级时间戳(将在v2.0版本移除,只保留 Timestamp)

func (Carbon) ToTimestampWithMicrosecond

func (c Carbon) ToTimestampWithMicrosecond() int64

ToTimestampWithMicrosecond outputs a timestamp with microsecond(will be removed from v2.0, only keep TimestampWithMicrosecond). 输出微秒级时间戳(将在v2.0版本移除,只保留 TimestampWithMicrosecond)

func (Carbon) ToTimestampWithMillisecond

func (c Carbon) ToTimestampWithMillisecond() int64

ToTimestampWithMillisecond outputs a timestamp with millisecond(will be removed from v2.0, only keep TimestampWithMillisecond). 输出毫秒级时间戳(将在v2.0版本移除,只保留 TimestampWithMillisecond)

func (Carbon) ToTimestampWithNanosecond

func (c Carbon) ToTimestampWithNanosecond() int64

ToTimestampWithNanosecond outputs a timestamp with nanosecond(will be removed from v2.0, only keep TimestampWithNanosecond). 输出纳秒级时间戳(将在v2.0版本移除,只保留 TimestampWithNanosecond)

func (Carbon) ToTimestampWithSecond

func (c Carbon) ToTimestampWithSecond() int64

ToTimestampWithSecond outputs a timestamp with second(will be removed from v2.0, only keep TimestampWithSecond). 输出秒级时间戳(将在v2.0版本移除,只保留 TimestampWithSecond)

func (Carbon) ToUnixDateString

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

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

func (Carbon) ToW3cString

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

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

func (Carbon) ToWeekString

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

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

func (Carbon) Tomorrow

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

Tomorrow returns 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

func (c Carbon) Week() int

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

func (Carbon) WeekOfMonth

func (c Carbon) WeekOfMonth() int

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

func (Carbon) WeekOfYear

func (c Carbon) WeekOfYear() int

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

func (Carbon) Year

func (c Carbon) Year() int

Year gets current year. 获取当前年

func (Carbon) Yesterday

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

Yesterday returns a Carbon instance for yesterday. 昨天

type Date

type Date struct {
	Carbon
}

Date defines a Date struct.

func (Date) MarshalJSON

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

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*Date) UnmarshalJSON

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

UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.

type DateTime

type DateTime struct {
	Carbon
}

DateTime defines a DateTime struct.

func (DateTime) MarshalJSON

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

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*DateTime) UnmarshalJSON

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

UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.

type Language

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

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

func NewLanguage

func NewLanguage() *Language

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

func (*Language) SetLocale

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

SetLocale sets language locale. 设置区域

func (*Language) SetResources

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

SetResources sets language resources. 设置资源

type Time

type Time struct {
	Carbon
}

Time defines a Time struct.

func (Time) MarshalJSON

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

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*Time) UnmarshalJSON

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

UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.

type Timestamp

type Timestamp struct {
	Carbon
}

Timestamp defines a Timestamp struct.

func (Timestamp) MarshalJSON

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

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*Timestamp) UnmarshalJSON

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

UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.

type TimestampWithMicrosecond

type TimestampWithMicrosecond struct {
	Carbon
}

TimestampWithMicrosecond defines a TimestampWithMicrosecond struct.

func (TimestampWithMicrosecond) MarshalJSON

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

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*TimestampWithMicrosecond) UnmarshalJSON

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

UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.

type TimestampWithMillisecond

type TimestampWithMillisecond struct {
	Carbon
}

TimestampWithMillisecond defines a TimestampWithMillisecond struct.

func (TimestampWithMillisecond) MarshalJSON

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

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*TimestampWithMillisecond) UnmarshalJSON

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

UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.

type TimestampWithNanosecond

type TimestampWithNanosecond struct {
	Carbon
}

TimestampWithNanosecond defines a TimestampWithNanosecond struct.

func (TimestampWithNanosecond) MarshalJSON

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

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*TimestampWithNanosecond) UnmarshalJSON

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

UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.

type TimestampWithSecond

type TimestampWithSecond struct {
	Carbon
}

TimestampWithSecond defines a TimestampWithSecond struct.

func (TimestampWithSecond) MarshalJSON

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

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*TimestampWithSecond) UnmarshalJSON

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

UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.

type ToDateString

type ToDateString struct {
	Carbon
}

ToDateString defines a ToDateString struct.

func (ToDateString) MarshalJSON

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

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*ToDateString) UnmarshalJSON

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

UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.

type ToDateTimeString

type ToDateTimeString struct {
	Carbon
}

ToDateTimeString defines a ToDateTimeString struct.

func (ToDateTimeString) MarshalJSON

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

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*ToDateTimeString) UnmarshalJSON

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

UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.

type ToTimeString

type ToTimeString struct {
	Carbon
}

ToTimeString defines a ToTimeString struct.

func (ToTimeString) MarshalJSON

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

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*ToTimeString) UnmarshalJSON

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

UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.

type ToTimestamp

type ToTimestamp struct {
	Carbon
}

ToTimestamp defines a ToTimestamp struct.

func (ToTimestamp) MarshalJSON

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

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*ToTimestamp) UnmarshalJSON

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

UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.

type ToTimestampWithMicrosecond

type ToTimestampWithMicrosecond struct {
	Carbon
}

ToTimestampWithMicrosecond defines a ToTimestampWithMicrosecond struct.

func (ToTimestampWithMicrosecond) MarshalJSON

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

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*ToTimestampWithMicrosecond) UnmarshalJSON

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

UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.

type ToTimestampWithMillisecond

type ToTimestampWithMillisecond struct {
	Carbon
}

ToTimestampWithMillisecond defines a ToTimestampWithMillisecond struct.

func (ToTimestampWithMillisecond) MarshalJSON

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

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*ToTimestampWithMillisecond) UnmarshalJSON

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

UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.

type ToTimestampWithNanosecond

type ToTimestampWithNanosecond struct {
	Carbon
}

ToTimestampWithNanosecond defines a ToTimestampWithNanosecond struct.

func (ToTimestampWithNanosecond) MarshalJSON

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

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*ToTimestampWithNanosecond) UnmarshalJSON

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

UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.

type ToTimestampWithSecond

type ToTimestampWithSecond struct {
	Carbon
}

ToTimestampWithSecond defines a ToTimestampWithSecond struct.

func (ToTimestampWithSecond) MarshalJSON

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

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*ToTimestampWithSecond) UnmarshalJSON

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 for i18n
Package lang is a part of the package carbon for i18n

Jump to

Keyboard shortcuts

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