mirror of
https://gitee.com/dromara/carbon.git
synced 2024-12-02 04:07:36 +08:00
添加N周前后方法
This commit is contained in:
parent
b3e47c6b64
commit
944620d9d7
@ -164,6 +164,15 @@ c.Now().SubMonths(3).ToDateTimeString() // 2020-06-08 13:00:00
|
|||||||
// 一月前
|
// 一月前
|
||||||
c.Now().SubMonth().ToDateTimeString() // 2020-08-08 13:00:00
|
c.Now().SubMonth().ToDateTimeString() // 2020-08-08 13:00:00
|
||||||
|
|
||||||
|
// 三周后
|
||||||
|
c.Now().AddWeeks(3).ToDateTimeString() // 2020-09-29 13:00:00
|
||||||
|
// 一周后
|
||||||
|
c.Now().AddWeek().ToDateTimeString() // 2020-09-15 13:00:00
|
||||||
|
// 三周前
|
||||||
|
c.Now().SubWeeks(3).ToDateTimeString() // 2020-08-17 13:00:00
|
||||||
|
// 一周前
|
||||||
|
c.Now().SubWeek().ToDateTimeString() // 2020-09-01 13:00:00
|
||||||
|
|
||||||
// 三天后
|
// 三天后
|
||||||
c.Now().AddDays(3).ToDateTimeString() // 2020-09-11 13:00:00
|
c.Now().AddDays(3).ToDateTimeString() // 2020-09-11 13:00:00
|
||||||
// 一天后
|
// 一天后
|
||||||
|
24
carbon.go
24
carbon.go
@ -120,6 +120,30 @@ func (c *Carbon) SubMonth() *Carbon {
|
|||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddWeeks N周后
|
||||||
|
func (c *Carbon) AddWeeks(weeks int) *Carbon {
|
||||||
|
c.Time = c.Time.AddDate(0, 0, weeks*7)
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddWeek 1周后
|
||||||
|
func (c *Carbon) AddWeek() *Carbon {
|
||||||
|
c.Time = c.Time.AddDate(0, 0, 7)
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SubWeeks N周前
|
||||||
|
func (c *Carbon) SubWeeks(weeks int) *Carbon {
|
||||||
|
c.Time = c.Time.AddDate(0, 0, -weeks*7)
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// SubMonth 减少1月
|
||||||
|
func (c *Carbon) SubWeek() *Carbon {
|
||||||
|
c.Time = c.Time.AddDate(0, 0, -7)
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
// AddDays N天后
|
// AddDays N天后
|
||||||
func (c *Carbon) AddDays(days int) *Carbon {
|
func (c *Carbon) AddDays(days int) *Carbon {
|
||||||
c.Time = c.Time.AddDate(0, 0, days)
|
c.Time = c.Time.AddDate(0, 0, days)
|
||||||
|
Loading…
Reference in New Issue
Block a user