代码拉取完成,页面将自动刷新
同步操作将从 dromara/carbon 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
package carbon_test
import (
"fmt"
"time"
"gitee.com/golang-package/carbon/v2"
)
func ExampleNewCarbon() {
loc, _ := time.LoadLocation(carbon.PRC)
t1, _ := time.Parse(carbon.DateTimeLayout, "2020-08-05 13:14:15")
t2, _ := time.ParseInLocation(carbon.DateTimeLayout, "2020-08-05 13:14:15", loc)
fmt.Println("go zero time:", time.Time{}.String())
fmt.Println("go zero time with timezone:", time.Time{}.In(loc).String())
fmt.Println("go valid time:", t1.String())
fmt.Println("go valid time with timezone:", t2.In(loc).String())
fmt.Println("carbon zero time:", carbon.NewCarbon().ToString())
fmt.Println("carbon zero time with timezone:", carbon.NewCarbon().SetLocation(loc).ToString())
fmt.Println("carbon valid time:", carbon.NewCarbon(t1).ToString())
fmt.Println("carbon valid time with timezone:", carbon.NewCarbon(t2).SetLocation(loc).ToString())
// Output:
// go zero time: 0001-01-01 00:00:00 +0000 UTC
// go zero time with timezone: 0001-01-01 08:05:43 +0805 LMT
// go valid time: 2020-08-05 13:14:15 +0000 UTC
// go valid time with timezone: 2020-08-05 13:14:15 +0800 CST
// carbon zero time: 0001-01-01 00:00:00 +0000 UTC
// carbon zero time with timezone: 0001-01-01 08:05:43 +0805 LMT
// carbon valid time: 2020-08-05 13:14:15 +0000 UTC
// carbon valid time with timezone: 2020-08-05 13:14:15 +0800 CST
}
func ExampleCarbon_Copy() {
oldCarbon := carbon.Parse("2020-08-05")
newCarbon := oldCarbon.Copy()
oldCarbon = oldCarbon.AddDay().SetLayout(carbon.DateTimeLayout).SetLocale("zh-CN").SetWeekStartsAt(carbon.Sunday)
fmt.Printf("old time: %s\n", oldCarbon.ToString())
fmt.Printf("new time: %s\n", newCarbon.ToString())
fmt.Printf("old layout: %s\n", oldCarbon.CurrentLayout())
fmt.Printf("new layout: %s\n", newCarbon.CurrentLayout())
fmt.Printf("old locale: %s\n", oldCarbon.Locale())
fmt.Printf("new locale: %s\n", newCarbon.Locale())
fmt.Printf("old week starts at: %s\n", oldCarbon.WeekStartsAt())
fmt.Printf("new week starts at: %s\n", newCarbon.WeekStartsAt())
// Output:
// old time: 2020-08-06 00:00:00 +0000 UTC
// new time: 2020-08-05 00:00:00 +0000 UTC
// old layout: 2006-01-02 15:04:05
// new layout: 2006-01-02
// old locale: zh-CN
// new locale: en
// old week starts at: Sunday
// new week starts at: Monday
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。