xtime

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2022 License: BSD-2-Clause, ISC, MIT Imports: 9 Imported by: 0

README

Xtime

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

English | 简体中文 | 日本語

Introduction

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

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

github.com/golang-module/xtime

gitee.com/go-package/xtime

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

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

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

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

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

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

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

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

Yesterday, today and tomorrow
// Return datetime of today
fmt.Sprintf("%s", xtime.Now()) // 2020-08-05 13:14:15
xtime.Now().ToDateTimeString() // 2020-08-05 13:14:15
// Return date of today
xtime.Now().ToDateString() // 2020-08-05
// Return time of today
xtime.Now().ToTimeString() // 13:14:15
// Return datetime of today in a given timezone
xtime.Now(Xtime.NewYork).ToDateTimeString() // 2020-08-05 14:14:15
xtime.SetTimezone(Xtime.NewYork).Now().ToDateTimeString() // 2020-08-05 14:14:15
// Return timestamp with second of today
xtime.Now().Timestamp() // 1596604455
xtime.Now().TimestampWithSecond() // 1596604455
// Return timestamp with millisecond of today
xtime.Now().TimestampWithMillisecond() // 1596604455000
// Return timestamp with microsecond of today
xtime.Now().TimestampWithMicrosecond() // 1596604455000000
// Return timestamp with nanosecond of today
xtime.Now().TimestampWithNanosecond() // 1596604455000000000

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

// Return datetime of tomorrow
fmt.Sprintf("%s", xtime.Tomorrow()) // 2020-08-06 13:14:15
xtime.Tomorrow().ToDateTimeString() // 2020-08-06 13:14:15
// Return date of tomorrow
xtime.Tomorrow().ToDateString() // 2020-08-06
// Return time of tomorrow
xtime.Tomorrow().ToTimeString() // 13:14:15
// Return datetime of tomorrow on a given day
xtime.Parse("2021-01-28 13:14:15").Tomorrow().ToDateTimeString() // 2021-01-29 13:14:15
// Return datetime of tomorrow in a given timezone
xtime.Tomorrow(Xtime.NewYork).ToDateTimeString() // 2020-08-06 14:14:15
xtime.SetTimezone(Xtime.NewYork).Tomorrow().ToDateTimeString() // 2020-08-06 14:14:15
// Return timestamp with second of tomorrow
xtime.Tomorrow().Timestamp() // 1596690855
xtime.Tomorrow().TimestampWithSecond() // 1596690855
// Return timestamp with millisecond of tomorrow
xtime.Tomorrow().TimestampWithMillisecond() // 1596690855000
// Return timestamp with microsecond of tomorrow
xtime.Tomorrow().TimestampWithMicrosecond() // 1596690855000000
// Return timestamp with nanosecond of tomorrow
xtime.Tomorrow().TimestampWithNanosecond() // 1596690855000000000
Create a Xtime instance
// Create a Xtime instance from a given timestamp with second
xtime.CreateFromTimestamp(-1).ToDateTimeString() // 1970-01-01 07:59:59
xtime.CreateFromTimestamp(-1, xtime.Tokyo).ToDateTimeString() // 1970-01-01 08:59:59
xtime.CreateFromTimestamp(0).ToDateTimeString() // 1970-01-01 08:00:00
xtime.CreateFromTimestamp(0, xtime.Tokyo).ToDateTimeString() // 1970-01-01 09:00:00
xtime.CreateFromTimestamp(1596604455).ToDateTimeString() // 2020-08-05 13:14:15
xtime.CreateFromTimestamp(1596604455, xtime.Tokyo).ToDateTimeString() // 2020-08-05 14:14:15
// Create a Xtime instance from a given timestamp with millisecond
xtime.CreateFromTimestamp(1596604455000).ToDateTimeString() // 2020-08-05 13:14:15
xtime.CreateFromTimestamp(1596604455000, xtime.Tokyo).ToDateTimeString() // 2020-08-05 14:14:15
// Create a Xtime instance from a given timestamp with microsecond
xtime.CreateFromTimestamp(1596604455000000).ToDateTimeString() // 2020-08-05 13:14:15
xtime.CreateFromTimestamp(1596604455000000, xtime.Tokyo).ToDateTimeString() // 2020-08-05 14:14:15
// Create a Xtime instance from a given timestamp with nanosecond
xtime.CreateFromTimestamp(1596604455000000000).ToDateTimeString() // 2020-08-05 13:14:15
xtime.CreateFromTimestamp(1596604455000000000, xtime.Tokyo).ToDateTimeString() // 2020-08-05 14:14:15

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

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

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

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

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

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

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

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

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

// Start of the second
xtime.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
xtime.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
xtime.Parse("2020-02-29 13:14:15").AddCenturies(3).ToDateTimeString() // 2320-02-29 13:14:15
// Add three centuries without overflowing month
xtime.Parse("2020-02-29 13:14:15").AddCenturiesNoOverflow(3).ToDateTimeString() // 2320-02-29 13:14:15
// Add one century
xtime.Parse("2020-02-29 13:14:15").AddCentury().ToDateTimeString() // 2120-02-29 13:14:15
// Add one century without overflowing month
xtime.Parse("2020-02-29 13:14:15").AddCenturyNoOverflow().ToDateTimeString() // 2120-02-29 13:14:15
// Subtract three centuries
xtime.Parse("2020-02-29 13:14:15").SubCenturies(3).ToDateTimeString() // 1720-02-29 13:14:15
// Subtract three centuries without overflowing month
xtime.Parse("2020-02-29 13:14:15").SubCenturiesNoOverflow(3).ToDateTimeString() // 1720-02-29 13:14:15
// Subtract one century
xtime.Parse("2020-02-29 13:14:15").SubCentury().ToDateTimeString() // 1920-02-29 13:14:15
// Subtract one century without overflowing month
xtime.Parse("2020-02-29 13:14:15").SubCenturyNoOverflow().ToDateTimeString() // 1920-02-20 13:14:15

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

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

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

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

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

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

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

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

// Add three seconds
xtime.Parse("2020-08-05 13:14:15").AddSeconds(3).ToDateTimeString() // 2020-08-05 13:14:18
// Add two and a half seconds
xtime.Parse("2020-08-05 13:14:15").AddDuration("2.5s").ToDateTimeString() // 2020-08-05 13:14:17
// Add one second
xtime.Parse("2020-08-05 13:14:15").AddSecond().ToDateTimeString() // 2020-08-05 13:14:16
// Subtract three seconds
xtime.Parse("2020-08-05 13:14:15").SubSeconds(3).ToDateTimeString() // 2020-08-05 13:14:12
// Subtract two and a half seconds
xtime.Parse("2020-08-05 13:14:15").SubDuration("2.5s").ToDateTimeString() // 2020-08-05 13:14:12
// Subtract one second
xtime.Parse("2020-08-05 13:14:15").SubSecond().ToDateTimeString() // 2020-08-05 13:14:14
Difference
// Difference in years
xtime.Parse("2021-08-05 13:14:15").DiffInYears(xtime.Parse("2020-08-05 13:14:15")) // -1
// Difference in years with absolute value
xtime.Parse("2021-08-05 13:14:15").DiffInYearsWithAbs(xtime.Parse("2020-08-05 13:14:15")) // 1

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// Whether between two Xtime instances, included the start and end Xtime instance
xtime.Parse("2020-08-05 13:14:15").BetweenIncludedBoth(xtime.Parse("2020-08-05 13:14:15"), xtime.Parse("2020-08-06 13:14:15")) // true
xtime.Parse("2020-08-05 13:14:15").BetweenIncludedBoth(xtime.Parse("2020-08-04 13:14:15"), xtime.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
xtime.SetTimezone(xtime.PRC).Now().ToDateTimeString() // 2020-08-05 13:14:15
xtime.SetTimezone(xtime.Tokyo).Now().ToDateTimeString() // 2020-08-05 14:14:15
xtime.SetTimezone(xtime.Tokyo).Now().SetTimezone(xtime.PRC).ToDateTimeString() // 2020-08-05 12:14:15

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

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

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

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

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

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

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

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

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

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

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

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

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

// Get timestamp with second, Timestamp() is shorthand for TimestampWithSecond()
xtime.Parse("2020-08-05 13:14:15").Timestamp() // 1596604455
xtime.Parse("2020-08-05 13:14:15").TimestampWithSecond() // 1596604455
// Get timestamp with millisecond
xtime.Parse("2020-08-05 13:14:15").TimestampWithMillisecond() // 1596604455000
// Get timestamp with microsecond
xtime.Parse("2020-08-05 13:14:15").TimestampWithMicrosecond() // 1596604455000000
// Get timestamp with nanosecond
xtime.Parse("2020-08-05 13:14:15").TimestampWithNanosecond() // 1596604455000000000

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

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

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

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

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

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

// Get current age
xtime.Parse("2002-01-01 13:14:15").Age() // 17
xtime.Parse("2002-12-31 13:14:15").Age() // 18
Output
// Output a string in date and time format
xtime.Parse("2020-08-05 13:14:15").ToDateTimeString() // 2020-08-05 13:14:15
xtime.Parse("2020-08-05 13:14:15").ToDateTimeString(xtime.Tokyo) // 2020-08-05 14:14:15
// Output a string in short date and time format
xtime.Parse("2020-08-05 13:14:15").ToShortDateTimeString() // 20200805131415
xtime.Parse("2020-08-05 13:14:15").ToShortDateTimeString(xtime.Tokyo) // 20200805141415

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

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

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

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

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

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

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

// Output a string by format, Format() is shorthand for ToFormatString()
xtime.Parse("2020-08-05 13:14:15").Format("YmdHis") // 20200805131415
xtime.Parse("2020-08-05 13:14:15").Format("Y年m月d日 H时i分s秒") // 2020年08月05日 13时14分15秒
xtime.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
xtime.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
xtime.Parse("2020-08-05 13:14:15").Format("Y-m-d H:i:s", xtime.Tokyo) // 2020-08-05 14:14:15

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

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

// Whether is Aries
xtime.Parse("2020-08-05 13:14:15").IsAries() // false
// Whether is Taurus
xtime.Parse("2020-08-05 13:14:15").IsTaurus() // false
// Whether is Gemini
xtime.Parse("2020-08-05 13:14:15").IsGemini() // false
// Whether is Cancer
xtime.Parse("2020-08-05 13:14:15").IsCancer() // false
// Whether is Leo
xtime.Parse("2020-08-05 13:14:15").IsLeo() // true
// Whether is Virgo
xtime.Parse("2020-08-05 13:14:15").IsVirgo() // false
// Whether is Libra
xtime.Parse("2020-08-05 13:14:15").IsLibra() // false
// Whether is Scorpio
xtime.Parse("2020-08-05 13:14:15").IsScorpio() // false
// Whether is Sagittarius
xtime.Parse("2020-08-05 13:14:15").IsSagittarius() // false
// Whether is Capricorn
xtime.Parse("2020-08-05 13:14:15").IsCapricorn() // false
// Whether is Aquarius
xtime.Parse("2020-08-05 13:14:15").IsAquarius() // false
// Whether is Pisces
xtime.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
xtime.Parse("2020-08-05 13:14:15").Season() // Summer

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

// Whether is spring
xtime.Parse("2020-08-05 13:14:15").IsSpring() // false
// Whether is summer
xtime.Parse("2020-08-05 13:14:15").IsSummer() // true
// Whether is autumn
xtime.Parse("2020-08-05 13:14:15").IsAutumn() // false
// Whether is winter
xtime.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
xtime.Parse("2020-08-05 13:14:15", xtime.PRC).Lunar().Animal() // 鼠

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

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

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

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

// Whether is a year of the rat
xtime.Parse("2020-08-05 13:14:15", xtime.PRC).Lunar().IsRatYear() // true
// Whether is a year of the ox
xtime.Parse("2020-08-05 13:14:15", xtime.PRC).Lunar().IsOxYear() // false
// Whether is a year of the tiger
xtime.Parse("2020-08-05 13:14:15", xtime.PRC).Lunar().IsTigerYear() // false
// Whether is a year of the rabbit
xtime.Parse("2020-08-05 13:14:15", xtime.PRC).Lunar().IsRabbitYear() // false
// Whether is a year of the dragon
xtime.Parse("2020-08-05 13:14:15", xtime.PRC).Lunar().IsDragonYear() // false
// Whether is a year of the snake
xtime.Parse("2020-08-05 13:14:15", xtime.PRC).Lunar().IsSnakeYear() // false
// Whether is a year of the horse
xtime.Parse("2020-08-05 13:14:15", xtime.PRC).Lunar().IsHorseYear() // false
// Whether is a year of the goat
xtime.Parse("2020-08-05 13:14:15", xtime.PRC).Lunar().IsGoatYear() // false
// Whether is a year of the monkey
xtime.Parse("2020-08-05 13:14:15", xtime.PRC).Lunar().IsMonkeyYear() // false
// Whether is a year of the rooster
xtime.Parse("2020-08-05 13:14:15", xtime.PRC).Lunar().IsRoosterYear() // false
// Whether is a year of the dog
xtime.Parse("2020-08-05 13:14:15", xtime.PRC).Lunar().IsDogYear() // false
// Whether is a year of the dig
xtime.Parse("2020-08-05 13:14:15", xtime.PRC).Lunar().IsPigYear() // false
JSON handling
Define model
type Person struct {
    ID  int64  `json:"id"`
    Name string `json:"name"`
    Age int `json:"age"`
    Birthday xtime.DateTime `json:"birthday"`
    GraduatedAt xtime.Date `json:"graduated_at"`
    CreatedAt xtime.Time `json:"created_at"`
    UpdatedAt xtime.Timestamp `json:"updated_at"`
    DateTime1 xtime.TimestampWithSecond `json:"date_time1"`
    DateTime2 xtime.TimestampWithMillisecond `json:"date_time2"`
    DateTime3 xtime.TimestampWithMicrosecond `json:"date_time3"`
    DateTime4 xtime.TimestampWithNanosecond `json:"date_time4"`
}
Instantiate model
person := Person {
    ID:          1,
    Name:        "gouguoyin",
    Age:         18,
    Birthday:    xtime.DateTime{xtime.Now().SubYears(18)},
    GraduatedAt: xtime.Date{xtime.Parse("2020-08-05 13:14:15")},
    CreatedAt:   xtime.Time{xtime.Parse("2021-08-05 13:14:15")},
    UpdatedAt:   xtime.Timestamp{xtime.Parse("2022-08-05 13:14:15")},
    DateTime1:   xtime.TimestampWithSecond{xtime.Parse("2023-08-05 13:14:15")},
    DateTime2:   xtime.TimestampWithMillisecond{xtime.Parse("2024-08-05 13:14:15")},
    DateTime3:   xtime.TimestampWithMicrosecond{xtime.Parse("2025-08-05 13:14:15")},
    DateTime4:   xtime.TimestampWithNanosecond{xtime.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 := xtime.NewLanguage()
lang.SetLocale("zh-CN")

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

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 := xtime.NewLanguage()
lang.SetLocale("en")

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

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

c.Now().AddYears(1).DiffForHumans() // 1 year from now
c.Now().AddHours(1).DiffForHumans() // 1h from now
c.Now().ToMonthString() // August
c.Now().ToShortMonthString() // Aug
c.Now().ToWeekString() // Tuesday
c.Now().ToShortWeekString() // Tue
c.Now().Constellation() // Leo
c.Now().Season() // Summer
Reset all resources
lang := xtime.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 := xtime.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 := xtime.SetTimezone(PRC).Parse("xxx")
if c.Error != nil {
    // Error handle...
    log.Fatal(c.Error)
}
fmt.Println(c.ToDateTimeString())
// Output
cannot parse "xxx" as xtime, please make sure the value is valid
Scene two
c := xtime.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 := xtime.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 xtime 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
	CookieFormat        = "Monday, 02-Jan-2006 15:04:05 MST"
	ISO8601Format       = "2006-01-02T15:04:05-07:00"
	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 Date

type Date struct {
	Xtime
}

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 {
	Xtime
}

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 {
	Error error
	// contains filtered or unexported fields
}

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

func NewLanguage

func NewLanguage() *Language

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

func (*Language) SetLocale

func (lang *Language) SetLocale(locale string)

SetLocale sets language locale. 设置区域

func (*Language) SetResources

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

SetResources sets language resources. 设置资源

type Time

type Time struct {
	Xtime
}

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 {
	Xtime
}

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 {
	Xtime
}

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 {
	Xtime
}

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 {
	Xtime
}

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 {
	Xtime
}

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 Xtime added in v0.0.3

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

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

func CreateFromDate

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

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

func CreateFromDateTime

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

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

func CreateFromTime

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

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

func CreateFromTimestamp

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

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

func NewXtime added in v0.0.3

func NewXtime() Xtime

NewXtime returns a new Xtime instance. 初始化 Xtime 结构体

func Now

func Now(timezone ...string) Xtime

Now returns a Xtime instance for now. 当前

func Parse

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

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

func ParseByFormat

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

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

func ParseByLayout

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

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

func SetLanguage

func SetLanguage(lang *Language) Xtime

SetLanguage sets language. 设置语言对象

func SetLocale

func SetLocale(locale string) Xtime

SetLocale sets locale. 设置语言区域

func SetTimezone

func SetTimezone(name string) Xtime

SetTimezone sets timezone. 设置时区

func Time2Xtime added in v0.0.3

func Time2Xtime(tt time.Time) Xtime

Time2Xtime converts time.Time to Xtime. 将 time.Time 转换成 Xtime

func Tomorrow

func Tomorrow(timezone ...string) Xtime

Tomorrow returns a Xtime instance for tomorrow. 明天

func Yesterday

func Yesterday(timezone ...string) Xtime

Yesterday returns a Xtime instance for yesterday. 昨天

func (Xtime) AddCenturies added in v0.0.3

func (c Xtime) AddCenturies(centuries int) Xtime

AddCenturies adds some centuries. N个世纪后

func (Xtime) AddCenturiesNoOverflow added in v0.0.3

func (c Xtime) AddCenturiesNoOverflow(centuries int) Xtime

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

func (Xtime) AddCentury added in v0.0.3

func (c Xtime) AddCentury() Xtime

AddCentury adds one century. 1个世纪后

func (Xtime) AddCenturyNoOverflow added in v0.0.3

func (c Xtime) AddCenturyNoOverflow() Xtime

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

func (Xtime) AddDay added in v0.0.3

func (c Xtime) AddDay() Xtime

AddDay adds one day. 1天后

func (Xtime) AddDays added in v0.0.3

func (c Xtime) AddDays(days int) Xtime

AddDays adds some days. N天后

func (Xtime) AddDecade added in v0.0.3

func (c Xtime) AddDecade() Xtime

AddDecade adds one decade. 1个年代后

func (Xtime) AddDecadeNoOverflow added in v0.0.3

func (c Xtime) AddDecadeNoOverflow() Xtime

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

func (Xtime) AddDecades added in v0.0.3

func (c Xtime) AddDecades(decades int) Xtime

AddDecades adds some decades. N个年代后

func (Xtime) AddDecadesNoOverflow added in v0.0.3

func (c Xtime) AddDecadesNoOverflow(decades int) Xtime

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

func (Xtime) AddDuration added in v0.0.3

func (c Xtime) AddDuration(duration string) Xtime

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

func (Xtime) AddHour added in v0.0.3

func (c Xtime) AddHour() Xtime

AddHour adds one hour. 1小时后

func (Xtime) AddHours added in v0.0.3

func (c Xtime) AddHours(hours int) Xtime

AddHours adds some hours. N小时后

func (Xtime) AddMinute added in v0.0.3

func (c Xtime) AddMinute() Xtime

AddMinute adds one minute. 1分钟后

func (Xtime) AddMinutes added in v0.0.3

func (c Xtime) AddMinutes(minutes int) Xtime

AddMinutes adds some minutes. N分钟后

func (Xtime) AddMonth added in v0.0.3

func (c Xtime) AddMonth() Xtime

AddMonth adds one month. 1个月后

func (Xtime) AddMonthNoOverflow added in v0.0.3

func (c Xtime) AddMonthNoOverflow() Xtime

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

func (Xtime) AddMonths added in v0.0.3

func (c Xtime) AddMonths(months int) Xtime

AddMonths adds some months. N个月后

func (Xtime) AddMonthsNoOverflow added in v0.0.3

func (c Xtime) AddMonthsNoOverflow(months int) Xtime

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

func (Xtime) AddQuarter added in v0.0.3

func (c Xtime) AddQuarter() Xtime

AddQuarter adds one quarter 1个季度后

func (Xtime) AddQuarterNoOverflow added in v0.0.3

func (c Xtime) AddQuarterNoOverflow() Xtime

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

func (Xtime) AddQuarters added in v0.0.3

func (c Xtime) AddQuarters(quarters int) Xtime

AddQuarters adds some quarters N个季度后

func (Xtime) AddQuartersNoOverflow added in v0.0.3

func (c Xtime) AddQuartersNoOverflow(quarters int) Xtime

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

func (Xtime) AddSecond added in v0.0.3

func (c Xtime) AddSecond() Xtime

AddSecond adds one second. 1秒钟后

func (Xtime) AddSeconds added in v0.0.3

func (c Xtime) AddSeconds(seconds int) Xtime

AddSeconds adds some seconds. N秒钟后

func (Xtime) AddWeek added in v0.0.3

func (c Xtime) AddWeek() Xtime

AddWeek adds one week. 1周后

func (Xtime) AddWeeks added in v0.0.3

func (c Xtime) AddWeeks(weeks int) Xtime

AddWeeks adds some weeks. N周后

func (Xtime) AddYear added in v0.0.3

func (c Xtime) AddYear() Xtime

AddYear adds one year. 1年后

func (Xtime) AddYearNoOverflow added in v0.0.3

func (c Xtime) AddYearNoOverflow() Xtime

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

func (Xtime) AddYears added in v0.0.3

func (c Xtime) AddYears(years int) Xtime

AddYears adds some years. N年后

func (Xtime) AddYearsNoOverflow added in v0.0.3

func (c Xtime) AddYearsNoOverflow(years int) Xtime

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

func (Xtime) Age added in v0.0.3

func (c Xtime) Age() int

Age gets age. 获取年龄

func (Xtime) Between added in v0.0.3

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

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

func (Xtime) BetweenIncludedBoth added in v0.0.3

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

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

func (Xtime) BetweenIncludedEnd added in v0.0.3

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

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

func (Xtime) BetweenIncludedStart added in v0.0.3

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

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

func (Xtime) Century added in v0.0.3

func (c Xtime) Century() int

Century gets current century. 获取当前世纪

func (Xtime) Compare added in v0.0.3

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

Compare compares by an operator. 时间比较

func (Xtime) Constellation added in v0.0.3

func (c Xtime) Constellation() string

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

func (Xtime) CreateFromDate added in v0.0.3

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

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

func (Xtime) CreateFromDateTime added in v0.0.3

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

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

func (Xtime) CreateFromTime added in v0.0.3

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

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

func (Xtime) CreateFromTimestamp added in v0.0.3

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

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

func (Xtime) Day added in v0.0.3

func (c Xtime) Day() int

Day gets current day. 获取当前日

func (Xtime) DayOfMonth added in v0.0.3

func (c Xtime) DayOfMonth() int

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

func (Xtime) DayOfWeek added in v0.0.3

func (c Xtime) DayOfWeek() int

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

func (Xtime) DayOfYear added in v0.0.3

func (c Xtime) DayOfYear() int

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

func (Xtime) DaysInMonth added in v0.0.3

func (c Xtime) DaysInMonth() int

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

func (Xtime) DaysInYear added in v0.0.3

func (c Xtime) DaysInYear() int

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

func (Xtime) Decade added in v0.0.3

func (c Xtime) Decade() int

Decade gets current decade. 获取当前年代

func (Xtime) DiffForHumans added in v0.0.3

func (c Xtime) DiffForHumans(xtime ...Xtime) string

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

func (Xtime) DiffInDays added in v0.0.3

func (c Xtime) DiffInDays(xtime ...Xtime) int64

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

func (Xtime) DiffInDaysWithAbs added in v0.0.3

func (c Xtime) DiffInDaysWithAbs(xtime ...Xtime) int64

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

func (Xtime) DiffInHours added in v0.0.3

func (c Xtime) DiffInHours(xtime ...Xtime) int64

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

func (Xtime) DiffInHoursWithAbs added in v0.0.3

func (c Xtime) DiffInHoursWithAbs(xtime ...Xtime) int64

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

func (Xtime) DiffInMinutes added in v0.0.3

func (c Xtime) DiffInMinutes(xtime ...Xtime) int64

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

func (Xtime) DiffInMinutesWithAbs added in v0.0.3

func (c Xtime) DiffInMinutesWithAbs(xtime ...Xtime) int64

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

func (Xtime) DiffInMonths added in v0.0.3

func (c Xtime) DiffInMonths(xtime ...Xtime) int64

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

func (Xtime) DiffInMonthsWithAbs added in v0.0.3

func (c Xtime) DiffInMonthsWithAbs(xtime ...Xtime) int64

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

func (Xtime) DiffInSeconds added in v0.0.3

func (c Xtime) DiffInSeconds(xtime ...Xtime) int64

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

func (Xtime) DiffInSecondsWithAbs added in v0.0.3

func (c Xtime) DiffInSecondsWithAbs(xtime ...Xtime) int64

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

func (Xtime) DiffInString added in v0.0.3

func (c Xtime) DiffInString(xtime ...Xtime) string

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

func (Xtime) DiffInStringWithAbs added in v0.0.3

func (c Xtime) DiffInStringWithAbs(xtime ...Xtime) string

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

func (Xtime) DiffInWeeks added in v0.0.3

func (c Xtime) DiffInWeeks(xtime ...Xtime) int64

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

func (Xtime) DiffInWeeksWithAbs added in v0.0.3

func (c Xtime) DiffInWeeksWithAbs(xtime ...Xtime) int64

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

func (Xtime) DiffInYears added in v0.0.3

func (c Xtime) DiffInYears(xtime ...Xtime) int64

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

func (Xtime) DiffInYearsWithAbs added in v0.0.3

func (c Xtime) DiffInYearsWithAbs(xtime ...Xtime) int64

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

func (Xtime) EndOfCentury added in v0.0.3

func (c Xtime) EndOfCentury() Xtime

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

func (Xtime) EndOfDay added in v0.0.3

func (c Xtime) EndOfDay() Xtime

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

func (Xtime) EndOfDecade added in v0.0.3

func (c Xtime) EndOfDecade() Xtime

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

func (Xtime) EndOfHour added in v0.0.3

func (c Xtime) EndOfHour() Xtime

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

func (Xtime) EndOfMinute added in v0.0.3

func (c Xtime) EndOfMinute() Xtime

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

func (Xtime) EndOfMonth added in v0.0.3

func (c Xtime) EndOfMonth() Xtime

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

func (Xtime) EndOfQuarter added in v0.0.3

func (c Xtime) EndOfQuarter() Xtime

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

func (Xtime) EndOfSeason added in v0.0.3

func (c Xtime) EndOfSeason() Xtime

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

func (Xtime) EndOfSecond added in v0.0.3

func (c Xtime) EndOfSecond() Xtime

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

func (Xtime) EndOfWeek added in v0.0.3

func (c Xtime) EndOfWeek() Xtime

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

func (Xtime) EndOfYear added in v0.0.3

func (c Xtime) EndOfYear() Xtime

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

func (Xtime) Eq added in v0.0.3

func (c Xtime) Eq(t Xtime) bool

Eq reports whether equal. 是否等于

func (Xtime) Format added in v0.0.3

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

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

func (Xtime) Gt added in v0.0.3

func (c Xtime) Gt(t Xtime) bool

Gt reports whether greater than. 是否大于

func (Xtime) Gte added in v0.0.3

func (c Xtime) Gte(t Xtime) bool

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

func (Xtime) Hour added in v0.0.3

func (c Xtime) Hour() int

Hour gets current hour. 获取当前小时

func (Xtime) IsApril added in v0.0.3

func (c Xtime) IsApril() bool

IsApril reports whether is April. 是否是四月

func (Xtime) IsAquarius added in v0.0.3

func (c Xtime) IsAquarius() bool

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

func (Xtime) IsAries added in v0.0.3

func (c Xtime) IsAries() bool

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

func (Xtime) IsAugust added in v0.0.3

func (c Xtime) IsAugust() bool

IsAugust reports whether is August. 是否是八月

func (Xtime) IsAutumn added in v0.0.3

func (c Xtime) IsAutumn() bool

IsAutumn reports whether is autumn. 是否是秋季

func (Xtime) IsCancer added in v0.0.3

func (c Xtime) IsCancer() bool

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

func (Xtime) IsCapricorn added in v0.0.3

func (c Xtime) IsCapricorn() bool

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

func (Xtime) IsDecember added in v0.0.3

func (c Xtime) IsDecember() bool

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

func (Xtime) IsFebruary added in v0.0.3

func (c Xtime) IsFebruary() bool

IsFebruary reports whether is February. 是否是二月

func (Xtime) IsFriday added in v0.0.3

func (c Xtime) IsFriday() bool

IsFriday reports whether is Friday. 是否是周五

func (Xtime) IsFuture added in v0.0.3

func (c Xtime) IsFuture() bool

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

func (Xtime) IsGemini added in v0.0.3

func (c Xtime) IsGemini() bool

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

func (Xtime) IsInvalid added in v0.0.3

func (c Xtime) IsInvalid() bool

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

func (Xtime) IsJanuary added in v0.0.3

func (c Xtime) IsJanuary() bool

IsJanuary reports whether is January. 是否是一月

func (Xtime) IsJuly added in v0.0.3

func (c Xtime) IsJuly() bool

IsJuly reports whether is July. 是否是七月

func (Xtime) IsJune added in v0.0.3

func (c Xtime) IsJune() bool

IsJune reports whether is June. 是否是六月

func (Xtime) IsLeapYear added in v0.0.3

func (c Xtime) IsLeapYear() bool

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

func (Xtime) IsLeo added in v0.0.3

func (c Xtime) IsLeo() bool

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

func (Xtime) IsLibra added in v0.0.3

func (c Xtime) IsLibra() bool

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

func (Xtime) IsLongYear added in v0.0.3

func (c Xtime) IsLongYear() bool

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

func (Xtime) IsMarch added in v0.0.3

func (c Xtime) IsMarch() bool

IsMarch reports whether is March. 是否是三月

func (Xtime) IsMay added in v0.0.3

func (c Xtime) IsMay() bool

IsMay reports whether is May. 是否是五月

func (Xtime) IsMonday added in v0.0.3

func (c Xtime) IsMonday() bool

IsMonday reports whether is Monday. 是否是周一

func (Xtime) IsNovember added in v0.0.3

func (c Xtime) IsNovember() bool

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

func (Xtime) IsNow added in v0.0.3

func (c Xtime) IsNow() bool

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

func (Xtime) IsOctober added in v0.0.3

func (c Xtime) IsOctober() bool

IsOctober reports whether is October. 是否是十月

func (Xtime) IsPast added in v0.0.3

func (c Xtime) IsPast() bool

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

func (Xtime) IsPisces added in v0.0.3

func (c Xtime) IsPisces() bool

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

func (Xtime) IsSagittarius added in v0.0.3

func (c Xtime) IsSagittarius() bool

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

func (Xtime) IsSaturday added in v0.0.3

func (c Xtime) IsSaturday() bool

IsSaturday reports whether is Saturday. 是否是周六

func (Xtime) IsScorpio added in v0.0.3

func (c Xtime) IsScorpio() bool

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

func (Xtime) IsSeptember added in v0.0.3

func (c Xtime) IsSeptember() bool

IsSeptember reports whether is September. 是否是九月

func (Xtime) IsSpring added in v0.0.3

func (c Xtime) IsSpring() bool

IsSpring reports whether is spring. 是否是春季

func (Xtime) IsSummer added in v0.0.3

func (c Xtime) IsSummer() bool

IsSummer reports whether is summer. 是否是夏季

func (Xtime) IsSunday added in v0.0.3

func (c Xtime) IsSunday() bool

IsSunday reports whether is Sunday. 是否是周日

func (Xtime) IsTaurus added in v0.0.3

func (c Xtime) IsTaurus() bool

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

func (Xtime) IsThursday added in v0.0.3

func (c Xtime) IsThursday() bool

IsThursday reports whether is Thursday. 是否是周四

func (Xtime) IsToday added in v0.0.3

func (c Xtime) IsToday() bool

IsToday reports whether is today. 是否是今天

func (Xtime) IsTomorrow added in v0.0.3

func (c Xtime) IsTomorrow() bool

IsTomorrow reports whether is tomorrow. 是否是明天

func (Xtime) IsTuesday added in v0.0.3

func (c Xtime) IsTuesday() bool

IsTuesday reports whether is Tuesday. 是否是周二

func (Xtime) IsVirgo added in v0.0.3

func (c Xtime) IsVirgo() bool

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

func (Xtime) IsWednesday added in v0.0.3

func (c Xtime) IsWednesday() bool

IsWednesday reports whether is Wednesday. 是否是周三

func (Xtime) IsWeekday added in v0.0.3

func (c Xtime) IsWeekday() bool

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

func (Xtime) IsWeekend added in v0.0.3

func (c Xtime) IsWeekend() bool

IsWeekend reports whether is weekend. 是否是周末

func (Xtime) IsWinter added in v0.0.3

func (c Xtime) IsWinter() bool

IsWinter reports whether is winter. 是否是冬季

func (Xtime) IsYesterday added in v0.0.3

func (c Xtime) IsYesterday() bool

IsYesterday reports whether is yesterday. 是否是昨天

func (Xtime) IsZero added in v0.0.3

func (c Xtime) IsZero() bool

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

func (Xtime) Layout added in v0.0.3

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

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

func (Xtime) Locale added in v0.0.3

func (c Xtime) Locale() string

Locale gets locale name. 获取语言区域

func (Xtime) Location added in v0.0.3

func (c Xtime) Location() string

Location gets location name. 获取位置

func (Xtime) Lt added in v0.0.3

func (c Xtime) Lt(t Xtime) bool

Lt reports whether less than. 是否小于

func (Xtime) Lte added in v0.0.3

func (c Xtime) Lte(t Xtime) bool

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

func (Xtime) Lunar added in v0.0.3

func (c Xtime) Lunar() (l lunar)

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

func (Xtime) Microsecond added in v0.0.3

func (c Xtime) Microsecond() int

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

func (Xtime) Millisecond added in v0.0.3

func (c Xtime) Millisecond() int

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

func (Xtime) Minute added in v0.0.3

func (c Xtime) Minute() int

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

func (Xtime) Month added in v0.0.3

func (c Xtime) Month() int

Month gets current month. 获取当前月

func (Xtime) MonthOfYear added in v0.0.3

func (c Xtime) MonthOfYear() int

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

func (Xtime) Nanosecond added in v0.0.3

func (c Xtime) Nanosecond() int

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

func (Xtime) Ne added in v0.0.3

func (c Xtime) Ne(t Xtime) bool

Ne reports whether not equal. 是否不等于

func (Xtime) Now added in v0.0.3

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

Now returns a Xtime instance for now. 当前

func (Xtime) Offset added in v0.0.3

func (c Xtime) Offset() int

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

func (Xtime) Parse added in v0.0.3

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

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

func (Xtime) ParseByFormat added in v0.0.3

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

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

func (Xtime) ParseByLayout added in v0.0.3

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

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

func (Xtime) Quarter added in v0.0.3

func (c Xtime) Quarter() (quarter int)

Quarter gets current quarter. 获取当前季度

func (*Xtime) Scan added in v0.0.3

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

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

func (Xtime) Season added in v0.0.3

func (c Xtime) Season() string

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

func (Xtime) Second added in v0.0.3

func (c Xtime) Second() int

Second gets current second. 获取当前秒数

func (Xtime) SetDay added in v0.0.3

func (c Xtime) SetDay(day int) Xtime

SetDay sets day. 设置日期

func (Xtime) SetHour added in v0.0.3

func (c Xtime) SetHour(hour int) Xtime

SetHour sets hour. 设置小时

func (Xtime) SetLanguage added in v0.0.3

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

SetLanguage sets language. 设置语言对象

func (Xtime) SetLocale added in v0.0.3

func (c Xtime) SetLocale(locale string) Xtime

SetLocale sets locale. 设置语言区域

func (Xtime) SetMicrosecond added in v0.0.3

func (c Xtime) SetMicrosecond(microsecond int) Xtime

SetMicrosecond sets microsecond. 设置微秒

func (Xtime) SetMillisecond added in v0.0.3

func (c Xtime) SetMillisecond(millisecond int) Xtime

SetMillisecond sets millisecond. 设置毫秒

func (Xtime) SetMinute added in v0.0.3

func (c Xtime) SetMinute(minute int) Xtime

SetMinute sets minute. 设置分钟

func (Xtime) SetMonth added in v0.0.3

func (c Xtime) SetMonth(month int) Xtime

SetMonth sets month. 设置月份

func (Xtime) SetMonthNoOverflow added in v0.0.3

func (c Xtime) SetMonthNoOverflow(month int) Xtime

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

func (Xtime) SetNanosecond added in v0.0.3

func (c Xtime) SetNanosecond(nanosecond int) Xtime

SetNanosecond sets nanosecond. 设置纳秒

func (Xtime) SetSecond added in v0.0.3

func (c Xtime) SetSecond(second int) Xtime

SetSecond sets second. 设置秒数

func (Xtime) SetTimezone added in v0.0.3

func (c Xtime) SetTimezone(name string) Xtime

SetTimezone sets timezone. 设置时区

func (Xtime) SetWeekStartsAt added in v0.0.3

func (c Xtime) SetWeekStartsAt(day string) Xtime

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

func (Xtime) SetYear added in v0.0.3

func (c Xtime) SetYear(year int) Xtime

SetYear sets year. 设置年份

func (Xtime) SetYearNoOverflow added in v0.0.3

func (c Xtime) SetYearNoOverflow(year int) Xtime

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

func (Xtime) StartOfCentury added in v0.0.3

func (c Xtime) StartOfCentury() Xtime

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

func (Xtime) StartOfDay added in v0.0.3

func (c Xtime) StartOfDay() Xtime

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

func (Xtime) StartOfDecade added in v0.0.3

func (c Xtime) StartOfDecade() Xtime

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

func (Xtime) StartOfHour added in v0.0.3

func (c Xtime) StartOfHour() Xtime

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

func (Xtime) StartOfMinute added in v0.0.3

func (c Xtime) StartOfMinute() Xtime

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

func (Xtime) StartOfMonth added in v0.0.3

func (c Xtime) StartOfMonth() Xtime

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

func (Xtime) StartOfQuarter added in v0.0.3

func (c Xtime) StartOfQuarter() Xtime

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

func (Xtime) StartOfSeason added in v0.0.3

func (c Xtime) StartOfSeason() Xtime

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

func (Xtime) StartOfSecond added in v0.0.3

func (c Xtime) StartOfSecond() Xtime

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

func (Xtime) StartOfWeek added in v0.0.3

func (c Xtime) StartOfWeek() Xtime

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

func (Xtime) StartOfYear added in v0.0.3

func (c Xtime) StartOfYear() Xtime

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

func (Xtime) String added in v0.0.3

func (c Xtime) String() string

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

func (Xtime) SubCenturies added in v0.0.3

func (c Xtime) SubCenturies(centuries int) Xtime

SubCenturies subtracts some centuries. N个世纪前

func (Xtime) SubCenturiesNoOverflow added in v0.0.3

func (c Xtime) SubCenturiesNoOverflow(centuries int) Xtime

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

func (Xtime) SubCentury added in v0.0.3

func (c Xtime) SubCentury() Xtime

SubCentury subtracts one century. 1个世纪前

func (Xtime) SubCenturyNoOverflow added in v0.0.3

func (c Xtime) SubCenturyNoOverflow() Xtime

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

func (Xtime) SubDay added in v0.0.3

func (c Xtime) SubDay() Xtime

SubDay subtracts one day. 1天前

func (Xtime) SubDays added in v0.0.3

func (c Xtime) SubDays(days int) Xtime

SubDays subtracts some days. N天前

func (Xtime) SubDecade added in v0.0.3

func (c Xtime) SubDecade() Xtime

SubDecade subtracts one decade. 1个年代后

func (Xtime) SubDecadeNoOverflow added in v0.0.3

func (c Xtime) SubDecadeNoOverflow() Xtime

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

func (Xtime) SubDecades added in v0.0.3

func (c Xtime) SubDecades(decades int) Xtime

SubDecades subtracts some decades. N个年代后

func (Xtime) SubDecadesNoOverflow added in v0.0.3

func (c Xtime) SubDecadesNoOverflow(decades int) Xtime

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

func (Xtime) SubDuration added in v0.0.3

func (c Xtime) SubDuration(duration string) Xtime

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

func (Xtime) SubHour added in v0.0.3

func (c Xtime) SubHour() Xtime

SubHour subtracts one hour. 1小时前

func (Xtime) SubHours added in v0.0.3

func (c Xtime) SubHours(hours int) Xtime

SubHours subtracts some hours. N小时前

func (Xtime) SubMinute added in v0.0.3

func (c Xtime) SubMinute() Xtime

SubMinute subtracts one minute. 1分钟前

func (Xtime) SubMinutes added in v0.0.3

func (c Xtime) SubMinutes(minutes int) Xtime

SubMinutes subtracts some minutes. N分钟前

func (Xtime) SubMonth added in v0.0.3

func (c Xtime) SubMonth() Xtime

SubMonth subtracts one month. 1个月前

func (Xtime) SubMonthNoOverflow added in v0.0.3

func (c Xtime) SubMonthNoOverflow() Xtime

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

func (Xtime) SubMonths added in v0.0.3

func (c Xtime) SubMonths(months int) Xtime

SubMonths subtracts some months. N个月前

func (Xtime) SubMonthsNoOverflow added in v0.0.3

func (c Xtime) SubMonthsNoOverflow(months int) Xtime

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

func (Xtime) SubQuarter added in v0.0.3

func (c Xtime) SubQuarter() Xtime

SubQuarter subtracts one quarter. 1个季度前

func (Xtime) SubQuarterNoOverflow added in v0.0.3

func (c Xtime) SubQuarterNoOverflow() Xtime

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

func (Xtime) SubQuarters added in v0.0.3

func (c Xtime) SubQuarters(quarters int) Xtime

SubQuarters subtracts some quarters. N个季度前

func (Xtime) SubQuartersNoOverflow added in v0.0.3

func (c Xtime) SubQuartersNoOverflow(quarters int) Xtime

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

func (Xtime) SubSecond added in v0.0.3

func (c Xtime) SubSecond() Xtime

SubSecond subtracts one second. 1秒钟前

func (Xtime) SubSeconds added in v0.0.3

func (c Xtime) SubSeconds(seconds int) Xtime

SubSeconds subtracts some seconds. N秒钟前

func (Xtime) SubWeek added in v0.0.3

func (c Xtime) SubWeek() Xtime

SubWeek subtracts one week. 1周前

func (Xtime) SubWeeks added in v0.0.3

func (c Xtime) SubWeeks(weeks int) Xtime

SubWeeks subtracts some weeks. N周前

func (Xtime) SubYear added in v0.0.3

func (c Xtime) SubYear() Xtime

SubYear subtracts one year. 1年前

func (Xtime) SubYearNoOverflow added in v0.0.3

func (c Xtime) SubYearNoOverflow() Xtime

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

func (Xtime) SubYears added in v0.0.3

func (c Xtime) SubYears(years int) Xtime

SubYears subtracts some years. N年前

func (Xtime) SubYearsNoOverflow added in v0.0.3

func (c Xtime) SubYearsNoOverflow(years int) Xtime

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

func (Xtime) Timestamp added in v0.0.3

func (c Xtime) Timestamp() int64

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

func (Xtime) TimestampWithMicrosecond added in v0.0.3

func (c Xtime) TimestampWithMicrosecond() int64

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

func (Xtime) TimestampWithMillisecond added in v0.0.3

func (c Xtime) TimestampWithMillisecond() int64

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

func (Xtime) TimestampWithNanosecond added in v0.0.3

func (c Xtime) TimestampWithNanosecond() int64

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

func (Xtime) TimestampWithSecond added in v0.0.3

func (c Xtime) TimestampWithSecond() int64

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

func (Xtime) Timezone added in v0.0.3

func (c Xtime) Timezone() string

Timezone gets timezone name. 获取时区

func (Xtime) ToAnsicString added in v0.0.3

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

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

func (Xtime) ToAtomString added in v0.0.3

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

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

func (Xtime) ToCookieString added in v0.0.3

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

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

func (Xtime) ToDateString added in v0.0.3

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

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

func (Xtime) ToDateTimeString added in v0.0.3

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

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

func (Xtime) ToDayDateTimeString added in v0.0.3

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

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

func (Xtime) ToFormatString added in v0.0.3

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

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

func (Xtime) ToIso8601String added in v0.0.3

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

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

func (Xtime) ToKitchenString added in v0.0.3

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

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

func (Xtime) ToLayoutString added in v0.0.3

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

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

func (Xtime) ToMonthString added in v0.0.3

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

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

func (Xtime) ToRfc1036String added in v0.0.3

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

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

func (Xtime) ToRfc1123String added in v0.0.3

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

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

func (Xtime) ToRfc1123zString added in v0.0.3

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

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

func (Xtime) ToRfc2822String added in v0.0.3

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

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

func (Xtime) ToRfc3339String added in v0.0.3

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

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

func (Xtime) ToRfc7231String added in v0.0.3

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

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

func (Xtime) ToRfc822String added in v0.0.3

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

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

func (Xtime) ToRfc822zString added in v0.0.3

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

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

func (Xtime) ToRfc850String added in v0.0.3

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

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

func (Xtime) ToRssString added in v0.0.3

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

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

func (Xtime) ToRubyDateString added in v0.0.3

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

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

func (Xtime) ToShortDateString added in v0.0.3

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

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

func (Xtime) ToShortDateTimeString added in v0.0.3

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

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

func (Xtime) ToShortMonthString added in v0.0.3

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

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

func (Xtime) ToShortTimeString added in v0.0.3

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

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

func (Xtime) ToShortWeekString added in v0.0.3

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

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

func (Xtime) ToString added in v0.0.3

func (c Xtime) 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 (Xtime) ToTimeString added in v0.0.3

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

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

func (Xtime) ToUnixDateString added in v0.0.3

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

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

func (Xtime) ToW3cString added in v0.0.3

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

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

func (Xtime) ToWeekString added in v0.0.3

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

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

func (Xtime) Tomorrow added in v0.0.3

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

Tomorrow returns a Xtime instance for tomorrow. 明天

func (Xtime) Value added in v0.0.3

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

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

func (Xtime) Week added in v0.0.3

func (c Xtime) Week() int

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

func (Xtime) WeekOfMonth added in v0.0.3

func (c Xtime) WeekOfMonth() int

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

func (Xtime) WeekOfYear added in v0.0.3

func (c Xtime) WeekOfYear() int

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

func (Xtime) Xtime2Time added in v0.0.3

func (c Xtime) Xtime2Time() time.Time

Xtime2Time converts Xtime to time.Time. 将 Xtime 转换成 time.Time

func (Xtime) Year added in v0.0.3

func (c Xtime) Year() int

Year gets current year. 获取当前年

func (Xtime) Yesterday added in v0.0.3

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

Yesterday returns a Xtime instance for yesterday. 昨天

Jump to

Keyboard shortcuts

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