diff --git a/routers/repo/user_data_analysis.go b/routers/repo/user_data_analysis.go index 07b2ad775..80045a5ad 100755 --- a/routers/repo/user_data_analysis.go +++ b/routers/repo/user_data_analysis.go @@ -290,7 +290,7 @@ func queryMetrics(ctx *context.Context, tableName string, startTime time.Time, e xlsx.SetActiveSheet(index) filename := sheetName + "_" + ctx.Tr("user.static."+tableName) + ".xlsx" if tableName == "" { - filename = sheetName + "_" + startTime.Add(8*60*60*1000).Format("20060102") + "_" + endTime.Add(8*60*60*1000).Format("20060102") + ".xlsx" + filename = sheetName + "_" + getTimeFileName(startTime) + "_" + getTimeFileName(endTime) + ".xlsx" } ctx.Resp.Header().Set("Content-Disposition", "attachment; filename="+url.QueryEscape(filename)) ctx.Resp.Header().Set("Content-Type", "application/octet-stream") @@ -312,7 +312,17 @@ func queryMetrics(ctx *context.Context, tableName string, startTime time.Time, e } ctx.JSON(http.StatusOK, mapInterface) } - +} +func getTimeFileName(t time.Time) string { + month := fmt.Sprint(t.Month()) + if t.Month() < 10 { + month = "0" + month + } + day := fmt.Sprint(t.Day()) + if t.Day() < 10 { + day = "0" + day + } + return fmt.Sprint(t.Year()) + month + day } func QueryRankingList(ctx *context.Context) {