Browse Source

fmt/check date & time

ls 5 years ago
parent
commit
61ffbff90f
1 changed files with 24 additions and 0 deletions
  1. 24 0
      fmt.go

+ 24 - 0
fmt.go

@@ -21,6 +21,30 @@ func IsTime(s string) bool {
 	return true
 }
 
+// IsDate 是否为有效日期
+func IsDate(s string) bool {
+	if _, e := time.Parse(DateFmtLong, s); e != nil {
+		return false
+	}
+	return true
+}
+
+// Str2Date 字符串转日期
+func Str2Date(s string) (t time.Time, err error) {
+	t, err = time.Parse(DateFmtLong, s)
+
+	return
+}
+
+// IsWeekEnd 日期是否周末
+func IsWeekEnd(d time.Weekday) bool {
+	day := int(d)
+	if day == 6 || day == 0 {
+		return true
+	}
+	return false
+}
+
 // Str2Time 字符串转时间
 func Str2Time(s string) (t time.Time, err error) {
 	t, err = time.Parse(TimeFmtLong, s)