From 7ca8b5f46295eb4a31a951d36655cb2cd8f3b8d6 Mon Sep 17 00:00:00 2001 From: Stanly Date: Mon, 31 Aug 2020 14:20:08 +0800 Subject: [PATCH] Add timestamp func date --- types/timestamp.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/types/timestamp.go b/types/timestamp.go index 7381285..460049d 100644 --- a/types/timestamp.go +++ b/types/timestamp.go @@ -6,6 +6,7 @@ import ( // 格式化 const ( + FormatDate = "2006-01-02" FormatDatetime = "2006-01-02 15:04:05" ) @@ -47,6 +48,14 @@ func (t Timestamp) Time() time.Time { return time.Unix(t.Int64(), 0) } +// Date 回傳日期字串 +func (t Timestamp) Date() string { + return time. + Unix(t.Int64(), 0). + In(Local). + Format(FormatDate) +} + // Datetime 回傳時間字串 func (t Timestamp) Datetime() string { return time.