From 01ff8fcca02666da4a2888e1d5ea3b3ff80dd9bc Mon Sep 17 00:00:00 2001 From: Peleus <245629560@qq.com> Date: Mon, 5 Feb 2024 12:00:22 +0800 Subject: [PATCH] optimize `ToW3cString` method --- outputer.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/outputer.go b/outputer.go index 62f51d34..99960794 100644 --- a/outputer.go +++ b/outputer.go @@ -476,7 +476,13 @@ func (c Carbon) ToRssString(timezone ...string) string { // ToW3cString outputs a string in "2006-01-02T15:04:05Z07:00" layout. // 输出 "2006-01-02T15:04:05Z07:00" 格式字符串 func (c Carbon) ToW3cString(timezone ...string) string { - return c.ToRfc3339String(timezone...) + if len(timezone) > 0 { + c.loc, c.Error = getLocationByTimezone(timezone[0]) + } + if c.IsInvalid() { + return "" + } + return c.StdTime().Format(W3cLayout) } // ToUnixDateString outputs a string in "Mon Jan _2 15:04:05 MST 2006" layout.