From e0ceb0ad0a559ef3d1b4b70e29bcdfa5a2a9ba63 Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 26 Jun 2018 18:40:37 +0800 Subject: [PATCH] - refactor timestr. --- utils/utils.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/utils/utils.go b/utils/utils.go index 36dc867a..dfafcdaa 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -146,19 +146,25 @@ func GetUUID() string { } func GetCurTimeStr() string { - return time.Now().Format("2006-01-02 15:04:05") + return Time2Str(time.Now()) } +// timestamp is in second func GetCurTimestamp() int64 { return time.Now().Unix() } func GetAPIOperator() string { - return time.Now().Format("2006-01-02_15:04:05") + return Time2Str(time.Now()) } +// timestamp is in second func Timestamp2Str(timestamp int64) string { - return time.Unix(timestamp/1000, 0).Format("2006-01-02 15:04:05") + return Time2Str(time.Unix(timestamp, 0)) +} + +func Time2Str(t time.Time) string { + return t.Format("2006-01-02 15:04:05") } func HTTPResponse2Json(response *http.Response) (map[string]interface{}, error) {