|
@@ -31,6 +31,7 @@ var (
|
|
|
}
|
|
|
)
|
|
|
|
|
|
+// ParseLocalDateTime 将日期时间字符串转换为time.Time,dateTime参数如果不是日期时间字符串会panic
|
|
|
func ParseLocalDateTime(dateTime string) *time.Time {
|
|
|
t, err := time.ParseInLocation(time.DateTime, dateTime, time.Local)
|
|
|
if err != nil {
|
|
@@ -40,6 +41,7 @@ func ParseLocalDateTime(dateTime string) *time.Time {
|
|
|
return &t
|
|
|
}
|
|
|
|
|
|
+// ParseLocalDateOnly 将日期字符串转换为time.Time,dateTime参数如果不是日期字符串会panic
|
|
|
func ParseLocalDateOnly(date string) *time.Time {
|
|
|
t, err := time.ParseInLocation(time.DateOnly, date, time.Local)
|
|
|
if err != nil {
|
|
@@ -49,14 +51,17 @@ func ParseLocalDateOnly(date string) *time.Time {
|
|
|
return &t
|
|
|
}
|
|
|
|
|
|
+// ParseNowDateOnly 将当前时间转换为time.Time,仅有日期信息
|
|
|
func ParseNowDateOnly() *time.Time {
|
|
|
return ParseLocalDateOnly(FormatNowDateOnly())
|
|
|
}
|
|
|
|
|
|
+// FormatNowDateTime 将当前时间转化为日期时间格式
|
|
|
func FormatNowDateTime() string {
|
|
|
return time.Now().Format(time.DateTime)
|
|
|
}
|
|
|
|
|
|
+// FormatLocalDateTime 将time.Time转化为日期时间格式
|
|
|
func FormatLocalDateTime(t *time.Time) string {
|
|
|
if t == nil {
|
|
|
return ""
|
|
@@ -65,10 +70,12 @@ func FormatLocalDateTime(t *time.Time) string {
|
|
|
return t.Format(time.DateTime)
|
|
|
}
|
|
|
|
|
|
+// FormatNowDateOnly 将当前时间转化为日期格式
|
|
|
func FormatNowDateOnly() string {
|
|
|
return time.Now().Format(time.DateOnly)
|
|
|
}
|
|
|
|
|
|
+// FormatLocalDateOnly 将time.Time转化为日期格式
|
|
|
func FormatLocalDateOnly(t *time.Time) string {
|
|
|
if t == nil {
|
|
|
return ""
|
|
@@ -77,6 +84,7 @@ func FormatLocalDateOnly(t *time.Time) string {
|
|
|
return t.Format(time.DateOnly)
|
|
|
}
|
|
|
|
|
|
+// GetYear 获取time.Time的年
|
|
|
func GetYear(t *time.Time) int {
|
|
|
if t == nil {
|
|
|
return 0
|
|
@@ -86,6 +94,7 @@ func GetYear(t *time.Time) int {
|
|
|
return year
|
|
|
}
|
|
|
|
|
|
+// GetWeek 获取time.Time的星期
|
|
|
func GetWeek(t *time.Time) int {
|
|
|
if t == nil {
|
|
|
return 0
|
|
@@ -95,6 +104,7 @@ func GetWeek(t *time.Time) int {
|
|
|
return week
|
|
|
}
|
|
|
|
|
|
+// DiffNatureDays 计算两个时间相差的天数
|
|
|
func DiffNatureDays(t1str string, t2str string) int {
|
|
|
t1 := ParseLocalDateTime(t1str).Unix()
|
|
|
t2 := ParseLocalDateTime(t2str).Unix()
|
|
@@ -126,6 +136,7 @@ func DiffNatureDays(t1str string, t2str string) int {
|
|
|
return diffDays
|
|
|
}
|
|
|
|
|
|
+// GetChinaMonth 获取中文表示的年
|
|
|
func GetChinaMonth(t *time.Time) string {
|
|
|
if t == nil {
|
|
|
return ""
|
|
@@ -135,6 +146,7 @@ func GetChinaMonth(t *time.Time) string {
|
|
|
return monthMap[month]
|
|
|
}
|
|
|
|
|
|
+// GetChinaWeek 获取中文表示的星期
|
|
|
func GetChinaWeek(t *time.Time) string {
|
|
|
if t == nil {
|
|
|
return ""
|