|
@@ -31,6 +31,7 @@ var (
|
|
|
}
|
|
|
)
|
|
|
|
|
|
+
|
|
|
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
|
|
|
}
|
|
|
|
|
|
+
|
|
|
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
|
|
|
}
|
|
|
|
|
|
+
|
|
|
func ParseNowDateOnly() *time.Time {
|
|
|
return ParseLocalDateOnly(FormatNowDateOnly())
|
|
|
}
|
|
|
|
|
|
+
|
|
|
func FormatNowDateTime() string {
|
|
|
return time.Now().Format(time.DateTime)
|
|
|
}
|
|
|
|
|
|
+
|
|
|
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)
|
|
|
}
|
|
|
|
|
|
+
|
|
|
func FormatNowDateOnly() string {
|
|
|
return time.Now().Format(time.DateOnly)
|
|
|
}
|
|
|
|
|
|
+
|
|
|
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)
|
|
|
}
|
|
|
|
|
|
+
|
|
|
func GetYear(t *time.Time) int {
|
|
|
if t == nil {
|
|
|
return 0
|
|
@@ -86,6 +94,7 @@ func GetYear(t *time.Time) int {
|
|
|
return year
|
|
|
}
|
|
|
|
|
|
+
|
|
|
func GetWeek(t *time.Time) int {
|
|
|
if t == nil {
|
|
|
return 0
|
|
@@ -95,6 +104,7 @@ func GetWeek(t *time.Time) int {
|
|
|
return week
|
|
|
}
|
|
|
|
|
|
+
|
|
|
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
|
|
|
}
|
|
|
|
|
|
+
|
|
|
func GetChinaMonth(t *time.Time) string {
|
|
|
if t == nil {
|
|
|
return ""
|
|
@@ -135,6 +146,7 @@ func GetChinaMonth(t *time.Time) string {
|
|
|
return monthMap[month]
|
|
|
}
|
|
|
|
|
|
+
|
|
|
func GetChinaWeek(t *time.Time) string {
|
|
|
if t == nil {
|
|
|
return ""
|