mirror of
https://gitee.com/dromara/carbon.git
synced 2024-12-02 12:17:37 +08:00
36 lines
870 B
Go
Executable File
36 lines
870 B
Go
Executable File
package carbon
|
|
|
|
import (
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
// format转layout
|
|
func format2layout(format string) string {
|
|
format = strings.Trim(format, " ")
|
|
layout := strings.Replace(format, "Y", "2006", 1)
|
|
layout = strings.Replace(layout, "y", "06", 1)
|
|
layout = strings.Replace(layout, "m", "01", 1)
|
|
layout = strings.Replace(layout, "n", "1", 1)
|
|
layout = strings.Replace(layout, "d", "02", 1)
|
|
layout = strings.Replace(layout, "j", "2", 1)
|
|
layout = strings.Replace(layout, "H", "15", 1)
|
|
layout = strings.Replace(layout, "h", "03", 1)
|
|
layout = strings.Replace(layout, "g", "3", 1)
|
|
layout = strings.Replace(layout, "i", "04", 1)
|
|
layout = strings.Replace(layout, "s", "05", 1)
|
|
return layout
|
|
}
|
|
|
|
// getDays 获取天数
|
|
func (c *Carbon) getDays() int {
|
|
days := 30
|
|
if c.Time.Month() == time.February {
|
|
days = 28
|
|
}
|
|
if c.IsLeapYear() {
|
|
days = days + 1
|
|
}
|
|
return days
|
|
}
|