@@ -21,6 +21,15 @@ func (c Carbon) String() string {
21
21
return c .ToDateTimeString (c .Location ())
22
22
}
23
23
24
+ // GoString implements fmt.GoStringer and formats c to be printed in Go source code.
25
+ // 实现 fmt.GoStringer 接口,并格式化 c 以在 Go 源代码中打印
26
+ func (c Carbon ) GoString () string {
27
+ if c .IsInvalid () {
28
+ return ""
29
+ }
30
+ return c .StdTime ().GoString ()
31
+ }
32
+
24
33
// ToString outputs a string in "2006-01-02 15:04:05.999999999 -0700 MST" layout.
25
34
// 输出 "2006-01-02 15:04:05.999999999 -0700 MST" 格式字符串
26
35
func (c Carbon ) ToString (timezone ... string ) string {
@@ -569,6 +578,54 @@ func (c Carbon) ToIso8601NanoString(timezone ...string) string {
569
578
return c .StdTime ().Format (ISO8601NanoLayout )
570
579
}
571
580
581
+ // ToIso8601ZuluString outputs a string in "2006-01-02T15:04:05Z" layout.
582
+ // 输出 "2006-01-02T15:04:05Z" 格式字符串
583
+ func (c Carbon ) ToIso8601ZuluString (timezone ... string ) string {
584
+ if len (timezone ) > 0 {
585
+ c .loc , c .Error = getLocationByTimezone (timezone [0 ])
586
+ }
587
+ if c .IsInvalid () {
588
+ return ""
589
+ }
590
+ return c .StdTime ().Format (ISO8601ZuluLayout )
591
+ }
592
+
593
+ // ToIso8601ZuluMilliString outputs a string in "2006-01-02T15:04:05.999Z" layout.
594
+ // 输出 "2006-01-02T15:04:05.999Z" 格式字符串
595
+ func (c Carbon ) ToIso8601ZuluMilliString (timezone ... string ) string {
596
+ if len (timezone ) > 0 {
597
+ c .loc , c .Error = getLocationByTimezone (timezone [0 ])
598
+ }
599
+ if c .IsInvalid () {
600
+ return ""
601
+ }
602
+ return c .StdTime ().Format (ISO8601ZuluMilliLayout )
603
+ }
604
+
605
+ // ToIso8601ZuluMicroString outputs a string in "2006-01-02T15:04:05.999999Z" layout.
606
+ // 输出 "2006-01-02T15:04:05.999999Z" 格式字符串
607
+ func (c Carbon ) ToIso8601ZuluMicroString (timezone ... string ) string {
608
+ if len (timezone ) > 0 {
609
+ c .loc , c .Error = getLocationByTimezone (timezone [0 ])
610
+ }
611
+ if c .IsInvalid () {
612
+ return ""
613
+ }
614
+ return c .StdTime ().Format (ISO8601ZuluMicroLayout )
615
+ }
616
+
617
+ // ToIso8601ZuluNanoString outputs a string in "2006-01-02T15:04:05.999999999Z" layout.
618
+ // 输出 "2006-01-02T15:04:05.999999999Z" 格式字符串
619
+ func (c Carbon ) ToIso8601ZuluNanoString (timezone ... string ) string {
620
+ if len (timezone ) > 0 {
621
+ c .loc , c .Error = getLocationByTimezone (timezone [0 ])
622
+ }
623
+ if c .IsInvalid () {
624
+ return ""
625
+ }
626
+ return c .StdTime ().Format (ISO8601ZuluNanoLayout )
627
+ }
628
+
572
629
// ToRfc822String outputs a string in "02 Jan 06 15:04 MST" layout.
573
630
// 输出 "02 Jan 06 15:04 MST" 格式字符串
574
631
func (c Carbon ) ToRfc822String (timezone ... string ) string {
@@ -713,27 +770,45 @@ func (c Carbon) ToRfc7231String(timezone ...string) string {
713
770
return c .StdTime ().Format (RFC7231Layout )
714
771
}
715
772
716
- // ToLayoutString outputs a string by layout.
717
- // 输出指定布局模板的时间字符串
718
- func (c Carbon ) ToLayoutString ( layout string , timezone ... string ) string {
773
+ // ToFormattedDateString outputs a string in "Jan 2, 2006" layout.
774
+ // 输出 "Jan 2, 2006" 格式字符串
775
+ func (c Carbon ) ToFormattedDateString ( timezone ... string ) string {
719
776
if len (timezone ) > 0 {
720
777
c .loc , c .Error = getLocationByTimezone (timezone [0 ])
721
778
}
722
779
if c .IsInvalid () {
723
780
return ""
724
781
}
725
- return c .StdTime ().Format (layout )
782
+ return c .StdTime ().Format (FormattedDateLayout )
726
783
}
727
784
728
- // Layout outputs a string by layout, it is shorthand for ToLayoutString.
729
- // 输出指定布局模板的时间字符串, 是 ToLayoutString 的简写
785
+ // ToFormattedDayDateString outputs a string in "Mon, Jan 2, 2006" layout.
786
+ // 输出 "Jan 2, 2006" 格式字符串
787
+ func (c Carbon ) ToFormattedDayDateString (timezone ... string ) string {
788
+ if len (timezone ) > 0 {
789
+ c .loc , c .Error = getLocationByTimezone (timezone [0 ])
790
+ }
791
+ if c .IsInvalid () {
792
+ return ""
793
+ }
794
+ return c .StdTime ().Format (FormattedDayDateLayout )
795
+ }
796
+
797
+ // Layout outputs a string by layout.
798
+ // 输出指定布局模板的时间字符串
730
799
func (c Carbon ) Layout (layout string , timezone ... string ) string {
731
- return c .ToLayoutString (layout , timezone ... )
800
+ if len (timezone ) > 0 {
801
+ c .loc , c .Error = getLocationByTimezone (timezone [0 ])
802
+ }
803
+ if c .IsInvalid () {
804
+ return ""
805
+ }
806
+ return c .StdTime ().Format (layout )
732
807
}
733
808
734
- // ToFormatString outputs a string by format.
809
+ // Format outputs a string by format.
735
810
// 输出指定格式模板的时间字符串
736
- func (c Carbon ) ToFormatString (format string , timezone ... string ) string {
811
+ func (c Carbon ) Format (format string , timezone ... string ) string {
737
812
if len (timezone ) > 0 {
738
813
c .loc , c .Error = getLocationByTimezone (timezone [0 ])
739
814
}
@@ -824,16 +899,10 @@ func (c Carbon) ToFormatString(format string, timezone ...string) string {
824
899
return buffer .String ()
825
900
}
826
901
827
- // Format outputs a string by format, it is shorthand for ToFormatString.
828
- // 输出指定格式模板的时间字符串, 是 ToFormatString 的简写
829
- func (c Carbon ) Format (format string , timezone ... string ) string {
830
- return c .ToFormatString (format , timezone ... )
831
- }
832
-
833
902
// Deprecated: it will be removed in the future, use StdTime instead.
834
903
//
835
904
// ToStdTime converts Carbon to standard time.Time.
836
- // 将 Carbon 转换成标准 time.Time,未来将移除,请用 StdTime 替换
905
+ // 将 Carbon 转换成标准 time.Time
837
906
func (c Carbon ) ToStdTime () time.Time {
838
907
return c .StdTime ()
839
908
}
0 commit comments