浏览代码

fix:时间格式

zqbao 10 月之前
父节点
当前提交
d95d29559c
共有 2 个文件被更改,包括 30 次插入8 次删除
  1. 4 4
      controllers/user.go
  2. 26 4
      utils/constants.go

+ 4 - 4
controllers/user.go

@@ -518,7 +518,7 @@ func (this *UserController) List() {
 		pars = append(pars, false)
 	}
 	if registerStartDate != "" {
-		registerStartTime, er := time.Parse("2006-01-02 15:04:05", registerStartDate)
+		registerStartTime, er := time.Parse(utils.FormatDate, registerStartDate)
 		if er != nil {
 			br.Msg = "日期格式有误"
 			return
@@ -527,7 +527,7 @@ func (this *UserController) List() {
 		pars = append(pars, registerStartTime)
 	}
 	if registerEndDate != "" {
-		registerEndTime, er := time.Parse("2006-01-02 15:04:05", registerEndDate)
+		registerEndTime, er := time.Parse(utils.FormatDate, registerEndDate)
 		if er != nil {
 			br.Msg = "日期格式有误"
 			return
@@ -536,7 +536,7 @@ func (this *UserController) List() {
 		pars = append(pars, registerEndTime)
 	}
 	if createStartDate != "" {
-		createStartTime, er := time.Parse("2006-01-02 15:04:05", createStartDate)
+		createStartTime, er := time.Parse(utils.FormatDate, createStartDate)
 		if er != nil {
 			br.Msg = "日期格式有误"
 			return
@@ -545,7 +545,7 @@ func (this *UserController) List() {
 		pars = append(pars, createStartTime)
 	}
 	if createEndDate != "" {
-		createEndTime, er := time.Parse("2006-01-02 15:04:05", createEndDate)
+		createEndTime, er := time.Parse(utils.FormatDate, createEndDate)
 		if er != nil {
 			br.Msg = "日期格式有误"
 			return

+ 26 - 4
utils/constants.go

@@ -10,12 +10,34 @@ const (
 	CACHE_ACCESS_TOKEN_LOGIN_NO_TRUST = "pc_eta_min_crm:login:no_trust:" //管理后台登录(不可信登录态)
 )
 
-const PageSize20 = 20
-const PageSize100 = 100
-const MaxDepartmentLevel = 3
-
 // 手机号,电子邮箱正则
 const (
 	RegularMobile = "^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0-9])|(17[0-9])|(16[0-9])|(19[0-9]))\\d{8}$" //手机号码
 	RegularEmail  = `\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*`                                             //匹配电子邮箱
 )
+
+// 常量定义
+const (
+	FormatTime                 = "15:04:05"                //时间格式
+	FormatTimeHm               = "15:04"                   //时间格式
+	FormatDate                 = "2006-01-02"              //日期格式
+	FormatDateUnSpace          = "20060102"                //日期格式
+	FormatDateTime             = "2006-01-02 15:04:05"     //完整时间格式
+	HlbFormatDateTime          = "2006-01-02_15:04:05.999" //完整时间格式
+	FormatDateTimeUnSpace      = "20060102150405"          //完整时间格式
+	FormatShortDateTimeUnSpace = "060102150405"            //省去开头两位年份的时间格式
+	EmptyDateTimeStr           = "0000-00-00 00:00:00"     //DateTime零值字符串
+	EmptyDateStr               = "0000-00-00"              //Date零值字符串
+	FormatMonthDayUnSpace      = "0102"                    //日期格式
+	FormatMonthDay             = "01-02"                   //日期格式
+	FormatYearMonthDate        = "2006-01"                 //日期格式
+	FormatYearDate             = "2006"                    //日期格式
+	PageSize15                 = 15                        //列表页每页数据量
+	PageSize5                  = 5
+	PageSize10                 = 10
+	PageSize20                 = 20
+	PageSize30                 = 30
+	PageSize50                 = 50
+	PageSize100                = 100
+	MaxDepartmentLevel         = 3
+)