Forráskód Böngészése

update time fmt & func

Ken 3 hete
szülő
commit
4931ebf082
2 módosított fájl, 19 hozzáadás és 0 törlés
  1. 12 0
      date.go
  2. 7 0
      db/const.go

+ 12 - 0
date.go

@@ -16,6 +16,12 @@ const (
 	DateFmtNumeric = `20060102`
 )
 
+// 时间日期格式长度
+const (
+	TimeLength = 19
+	DateLength = 10
+)
+
 // IsTime 是否时间格式字符串
 func IsTime(s string) bool {
 	if _, err := time.Parse(TimeFmtLong, s); err != nil {
@@ -76,6 +82,12 @@ func StrFmtLocationTime(s, fmt string) (t time.Time, err error) {
 	return
 }
 
+// StrToLocationDate 字符串转日期
+func StrToLocationDate(s string) (t time.Time, err error) {
+	t, err = time.ParseInLocation(DateFmtLong, s, time.Local)
+	return
+}
+
 // IsWeekEnd 日期是否周末
 func IsWeekEnd(d time.Weekday) bool {
 	day := int(d)

+ 7 - 0
db/const.go

@@ -0,0 +1,7 @@
+package db
+
+// PostgreSQL 日期时间格式化格式
+const (
+	PgDateTimeFmt = `yyyy-mm-dd hh24:mi:ss` // 带时间
+	PgDateFmt     = `yyyy-mm-dd`            // 仅日期
+)