v2.1.6 更新文档

This commit is contained in:
gouguoyin 2022-05-07 06:57:43 +00:00 committed by Gitee
parent 0e9ffc8fca
commit 492670d0f2
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 110 additions and 108 deletions

View File

@ -1185,41 +1185,42 @@ carbon.Parse("2020-03-21 21:00:00").Lunar().IsTwelfthDoubleHour() // true
```go
type Person struct {
Name string `json:"name"`
Age int `json:"age"`
Birthday1 carbon.DateTime `json:"birthday"`
Birthday2 carbon.DateTimeMilli `json:"birthday"`
Birthday3 carbon.DateTimeMicro `json:"birthday"`
Birthday4 carbon.DateTimeNano `json:"birthday"`
GraduatedAt1 carbon.Date `json:"graduated_at"`
GraduatedAt2 carbon.DateMilli `json:"graduated_at"`
GraduatedAt3 carbon.DateMicro `json:"graduated_at"`
GraduatedAt4 carbon.DateNano `json:"graduated_at"`
CreatedAt1 carbon.Timestamp `json:"created_at1"`
CreatedAt2 carbon.TimestampMilli `json:"created_at2"`
CreatedAt3 carbon.TimestampMicro `json:"created_at3"`
CreatedAt4 carbon.TimestampNano `json:"created_at4"`
Name string `json:"name"`
Age int `json:"age"`
Birthday1 carbon.DateTime `json:"birthday"`
Birthday2 carbon.DateTimeMilli `json:"birthday"`
Birthday3 carbon.DateTimeMicro `json:"birthday"`
Birthday4 carbon.DateTimeNano `json:"birthday"`
GraduatedAt1 carbon.Date `json:"graduated_at"`
GraduatedAt2 carbon.DateMilli `json:"graduated_at"`
GraduatedAt3 carbon.DateMicro `json:"graduated_at"`
GraduatedAt4 carbon.DateNano `json:"graduated_at"`
CreatedAt1 carbon.Timestamp `json:"created_at1"`
CreatedAt2 carbon.TimestampMilli `json:"created_at2"`
CreatedAt3 carbon.TimestampMicro `json:"created_at3"`
CreatedAt4 carbon.TimestampNano `json:"created_at4"`
}
```
###### 实例化模型
```go
now := carbon.Now()
person := Person {
Name: "gouguoyin",
Age: 18,
Birthday1: carbon.DateTime{carbon.Now().SubYears(18)},
Birthday2: carbon.DateTime{carbon.Now().SubYears(18)},
Birthday3: carbon.DateTime{carbon.Now().SubYears(18)},
Birthday4: carbon.DateTime{carbon.Now().SubYears(18)},
GraduatedAt1: carbon.Date{carbon.Now()},
GraduatedAt2: carbon.Date{carbon.Now()},
GraduatedAt3: carbon.Date{carbon.Now()},
GraduatedAt4: carbon.Date{carbon.Now()},
CreatedAt1: carbon.Timestamp{carbon.Now()},
CreatedAt2: carbon.TimestampMilli{carbon.Now()},
CreatedAt3: carbon.TimestampMicro{carbon.Now()},
CreatedAt4: carbon.TimestampNano{carbon.Now()},
Name: "gouguoyin",
Age: 18,
Birthday1: carbon.DateTime{now.SubYears(18)},
Birthday2: carbon.DateTime{now.SubYears(18)},
Birthday3: carbon.DateTime{now.SubYears(18)},
Birthday4: carbon.DateTime{now.SubYears(18)},
GraduatedAt1: carbon.Date{now},
GraduatedAt2: carbon.Date{now},
GraduatedAt3: carbon.Date{now},
GraduatedAt4: carbon.Date{now},
CreatedAt1: carbon.Timestamp{now},
CreatedAt2: carbon.TimestampMilli{now},
CreatedAt3: carbon.TimestampMicro{now},
CreatedAt4: carbon.TimestampNano{now},
}
```
@ -1228,26 +1229,26 @@ CreatedAt4: carbon.TimestampNano{carbon.Now()},
```go
data, err := json.Marshal(&person)
if err != nil {
// 错误处理
log.Fatal(err)
// 错误处理
log.Fatal(err)
}
fmt.Printf("%s", data)
// 输出
{
"name": "gouguoyin",
"age": 18,
"birthday1": "2003-07-16 16:22:02",
"birthday2": "2003-07-16 16:22:02.999",
"birthday3": "2003-07-16 16:22:02.999999",
"birthday4": "2003-07-16 16:22:02.999999999",
"graduated_at1": "2020-08-05",
"graduated_at2": "2020-08-05.999",
"graduated_at3": "2020-08-05.999999",
"graduated_at4": "2020-08-05.999999999",
"created_at1": 1596604455,
"created_at2": 1596604455999,
"created_at3": 1596604455999999,
"created_at4": 1596604455999999999
"name": "gouguoyin",
"age": 18,
"birthday1": "2003-07-16 16:22:02",
"birthday2": "2003-07-16 16:22:02.999",
"birthday3": "2003-07-16 16:22:02.999999",
"birthday4": "2003-07-16 16:22:02.999999999",
"graduated_at1": "2020-08-05",
"graduated_at2": "2020-08-05.999",
"graduated_at3": "2020-08-05.999999",
"graduated_at4": "2020-08-05.999999999",
"created_at1": 1596604455,
"created_at2": 1596604455999,
"created_at3": 1596604455999999,
"created_at4": 1596604455999999999
}
```
@ -1273,8 +1274,8 @@ str := `{
person := new(Person)
err := json.Unmarshal([]byte(str), &person)
if err != nil {
// 错误处理
log.Fatal(err)
// 错误处理
log.Fatal(err)
}
fmt.Printf("%+v", *person)
// 输出

View File

@ -1181,41 +1181,42 @@ carbon.Parse("2020-03-21 21:00:00").Lunar().IsTwelfthDoubleHour() // true
```go
type Person struct {
Name string `json:"name"`
Age int `json:"age"`
Birthday1 carbon.DateTime `json:"birthday"`
Birthday2 carbon.DateTimeMilli `json:"birthday"`
Birthday3 carbon.DateTimeMicro `json:"birthday"`
Birthday4 carbon.DateTimeNano `json:"birthday"`
GraduatedAt1 carbon.Date `json:"graduated_at"`
GraduatedAt2 carbon.DateMilli `json:"graduated_at"`
GraduatedAt3 carbon.DateMicro `json:"graduated_at"`
GraduatedAt4 carbon.DateNano `json:"graduated_at"`
CreatedAt1 carbon.Timestamp `json:"created_at1"`
CreatedAt2 carbon.TimestampMilli `json:"created_at2"`
CreatedAt3 carbon.TimestampMicro `json:"created_at3"`
CreatedAt4 carbon.TimestampNano `json:"created_at4"`
Name string `json:"name"`
Age int `json:"age"`
Birthday1 carbon.DateTime `json:"birthday"`
Birthday2 carbon.DateTimeMilli `json:"birthday"`
Birthday3 carbon.DateTimeMicro `json:"birthday"`
Birthday4 carbon.DateTimeNano `json:"birthday"`
GraduatedAt1 carbon.Date `json:"graduated_at"`
GraduatedAt2 carbon.DateMilli `json:"graduated_at"`
GraduatedAt3 carbon.DateMicro `json:"graduated_at"`
GraduatedAt4 carbon.DateNano `json:"graduated_at"`
CreatedAt1 carbon.Timestamp `json:"created_at1"`
CreatedAt2 carbon.TimestampMilli `json:"created_at2"`
CreatedAt3 carbon.TimestampMicro `json:"created_at3"`
CreatedAt4 carbon.TimestampNano `json:"created_at4"`
}
```
###### 初期化モデル
```go
now := carbon.Now()
person := Person {
Name: "gouguoyin",
Age: 18,
Birthday1: carbon.DateTime{carbon.Now().SubYears(18)},
Birthday2: carbon.DateTime{carbon.Now().SubYears(18)},
Birthday3: carbon.DateTime{carbon.Now().SubYears(18)},
Birthday4: carbon.DateTime{carbon.Now().SubYears(18)},
GraduatedAt1: carbon.Date{carbon.Now()},
GraduatedAt2: carbon.Date{carbon.Now()},
GraduatedAt3: carbon.Date{carbon.Now()},
GraduatedAt4: carbon.Date{carbon.Now()},
CreatedAt1: carbon.Timestamp{carbon.Now()},
CreatedAt2: carbon.TimestampMilli{carbon.Now()},
CreatedAt3: carbon.TimestampMicro{carbon.Now()},
CreatedAt4: carbon.TimestampNano{carbon.Now()},
Name: "gouguoyin",
Age: 18,
Birthday1: carbon.DateTime{now.SubYears(18)},
Birthday2: carbon.DateTime{now.SubYears(18)},
Birthday3: carbon.DateTime{now.SubYears(18)},
Birthday4: carbon.DateTime{now.SubYears(18)},
GraduatedAt1: carbon.Date{now},
GraduatedAt2: carbon.Date{now},
GraduatedAt3: carbon.Date{now},
GraduatedAt4: carbon.Date{now},
CreatedAt1: carbon.Timestamp{now},
CreatedAt2: carbon.TimestampMilli{now},
CreatedAt3: carbon.TimestampMicro{now},
CreatedAt4: carbon.TimestampNano{now},
}
```
@ -1224,26 +1225,26 @@ CreatedAt4: carbon.TimestampNano{carbon.Now()},
```go
data, err := json.Marshal(&person)
if err != nil {
// エラー処理...
log.Fatal(c.Error)
// エラー処理...
log.Fatal(c.Error)
}
fmt.Printf("%s", data)
// 出力
{
"name": "gouguoyin",
"age": 18,
"birthday1": "2003-07-16 16:22:02",
"birthday2": "2003-07-16 16:22:02.999",
"birthday3": "2003-07-16 16:22:02.999999",
"birthday4": "2003-07-16 16:22:02.999999999",
"graduated_at1": "2020-08-05",
"graduated_at2": "2020-08-05.999",
"graduated_at3": "2020-08-05.999999",
"graduated_at4": "2020-08-05.999999999",
"created_at1": 1596604455,
"created_at2": 1596604455999,
"created_at3": 1596604455999999,
"created_at4": 1596604455999999999
"name": "gouguoyin",
"age": 18,
"birthday1": "2003-07-16 16:22:02",
"birthday2": "2003-07-16 16:22:02.999",
"birthday3": "2003-07-16 16:22:02.999999",
"birthday4": "2003-07-16 16:22:02.999999999",
"graduated_at1": "2020-08-05",
"graduated_at2": "2020-08-05.999",
"graduated_at3": "2020-08-05.999999",
"graduated_at4": "2020-08-05.999999999",
"created_at1": 1596604455,
"created_at2": 1596604455999,
"created_at3": 1596604455999999,
"created_at4": 1596604455999999999
}
```
@ -1269,8 +1270,8 @@ str := `{
person := new(Person)
err := json.Unmarshal([]byte(str), &person)
if err != nil {
// エラー処理...
log.Fatal(c.Error)
// エラー処理...
log.Fatal(c.Error)
}
fmt.Printf("%+v", *person)
// 出力
@ -1311,8 +1312,8 @@ lang.SetLocale("jp")
c := carbon.SetLanguage(lang)
if c.Error != nil {
// エラー処理
log.Fatal(err)
// エラー処理
log.Fatal(err)
}
c.Now().AddHours(1).DiffForHumans() // 1 時間後

View File

@ -1180,20 +1180,20 @@ carbon.Parse("2020-03-21 21:00:00").Lunar().IsTwelfthDoubleHour() // true
```go
type Person struct {
Name string `json:"name"`
Age int `json:"age"`
Birthday1 carbon.DateTime `json:"birthday"`
Birthday2 carbon.DateTimeMilli `json:"birthday"`
Birthday3 carbon.DateTimeMicro `json:"birthday"`
Birthday4 carbon.DateTimeNano `json:"birthday"`
GraduatedAt1 carbon.Date `json:"graduated_at"`
GraduatedAt2 carbon.DateMilli `json:"graduated_at"`
GraduatedAt3 carbon.DateMicro `json:"graduated_at"`
GraduatedAt4 carbon.DateNano `json:"graduated_at"`
CreatedAt1 carbon.Timestamp `json:"created_at1"`
CreatedAt2 carbon.TimestampMilli `json:"created_at2"`
CreatedAt3 carbon.TimestampMicro `json:"created_at3"`
CreatedAt4 carbon.TimestampNano `json:"created_at4"`
Name string `json:"name"`
Age int `json:"age"`
Birthday1 carbon.DateTime `json:"birthday"`
Birthday2 carbon.DateTimeMilli `json:"birthday"`
Birthday3 carbon.DateTimeMicro `json:"birthday"`
Birthday4 carbon.DateTimeNano `json:"birthday"`
GraduatedAt1 carbon.Date `json:"graduated_at"`
GraduatedAt2 carbon.DateMilli `json:"graduated_at"`
GraduatedAt3 carbon.DateMicro `json:"graduated_at"`
GraduatedAt4 carbon.DateNano `json:"graduated_at"`
CreatedAt1 carbon.Timestamp `json:"created_at1"`
CreatedAt2 carbon.TimestampMilli `json:"created_at2"`
CreatedAt3 carbon.TimestampMicro `json:"created_at3"`
CreatedAt4 carbon.TimestampNano `json:"created_at4"`
}
```