Comments (11)
The issue body's language is not English, translate it automatically, please use English next time. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
Starting from v2.3.0, after removing the DateTime and other series of methods, now use gorm to insert the field containing birthday (Y-m-d). The front-end passes Y-m-d, and the background keeps reporting the layout "2006-01-02 15:04:05" error. Carbon is set. :"type:date" still doesn't work. The same problem exists when querying a list. It seems that json serialization and deserialization will not recognize the set Tag parameters, which is extremely inconvenient. What is the best practice? @@=== =Starting from v2.3.0, after removing DateTime and other series of methods, now use gorm to insert the birthday (Y-m-d) field. It is extremely inconvenient. What is the best practice?
from carbon.
https://github.com/golang-module/carbon/blob/master/README.cn.md#json
from carbon.
建议在项目入口文件(如 main.go
)里设置全局模板格式、时区等
carbon.SetDefault(carbon.Default{
Layout: carbon.RFC3339Layout,
Timezone: carbon.PRC,
WeekStartsAt: carbon.Sunday,
Locale: "zh-CN",
})
from carbon.
The issue body's language is not English, translate it automatically, please use English next time. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
It is recommended to set the global template format, time zone, etc. in the project entry file (such as main.go
)
carbon.SetDefault(carbon.Default{
Layout: carbon.RFC3339Layout,
Timezone: carbon.PRC,
WeekStartsAt: carbon.Sunday,
Locale: "zh-CN",
})
from carbon.
这个SetDefault 是很好的,但是略显鸡肋,部分非标准layout还是没有之前用起来顺畅,要是能解决json序列化,反序列能读取设置的非标准tag就好了
from carbon.
The issue body's language is not English, translate it automatically, please use English next time. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
This SetDefault is very good, but it is a bit useless. Some non-standard layouts are still not as smooth to use as before. It would be great if json serialization can be solved and the non-standard tags set can be read by deserialization.
from carbon.
这个SetDefault 是很好的,但是略显鸡肋,部分非标准layout还是没有之前用起来顺畅,要是能解决json序列化,反序列能读取设置的非标准tag就好了
之前是预置的固定类型,没有预置的就没办法处理,现在使用 SetDefault
把控制权交给了用户,SetDefault
可以设置任何标准或非标准的 layout
,如
carbon.SetDefault(carbon.Default{
Layout: "2006/1/2",
})
from carbon.
The issue body's language is not English, translate it automatically, please use English next time. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
This SetDefault is very good, but it is a bit useless. Some non-standard layouts are still not as smooth to use as before. It would be great if json serialization could be solved and the non-standard tags set could be read by deserialization.
It used to be a preset fixed type. If there is no preset, there is no way to process it. Now use SetDefault
to give control to the user. SetDefault
can set any standard or non-standard layout
from carbon.
如果要使用 tag
也可以,不过使用了泛型,性能会受到影响。使用 tag
序列化或者反序列化前必须调用 carbon.loadTag
方法载入 tag
from carbon.
总结起来
1、如果结构体里时间字段输出格式都一样,使用 carbon.SetDefault
方法(当然也可以用 tag
,不过不推荐)
2、如果结构体里时间字段输出格式不一样,只能使用 tag
配合 carbon.LoadTag
方法
from carbon.
The issue body's language is not English, translate it automatically, please use English next time. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
In short
- If the output format of the time fields in the structure is the same, use
carbon.SetDefault
- If the output format of the time field in the structure is different, use
tag
withcarbon.LoadTag
from carbon.
Related Issues (20)
- 咨询关于Now函数入参的问题(About the Now function parameter issue) HOT 1
- `ToWeekString()` ignores `SetWeekStartsAt()`
- The current JSON serialization format is `2006-01-02 15:04:05.999999999`. Is user-defined configuration allowed? HOT 5
- "2023-11-08T09:52:48" not support? HOT 5
- Rename the func such as `carbon.CreateFromDate()`. HOT 13
- ParseByFormat not supported "U" format HOT 3
- json is reversed, causing the diff series method to be abnormal. What should I do in this case? HOT 5
- My local time is Asia/Shanghai, But the time from the database is UTC HOT 6
- Default JSON template settings HOT 1
- Wrong zodiac sign HOT 2
- build for windows_386 (untyped int constant) overflows int HOT 6
- How to get time.Duration in two carbon instances? ? HOT 1
- ParseByFormat fails to detect location Location HOT 2
- cannot parse string null HOT 3
- DiffAbsInDuration must upgrade go version to 1.9+ HOT 3
- Can you add the 1.5.5 tag? HOT 4
- Incorrect Parse of 0001-01-01 00:00:00 HOT 7
- How to loadTag a slice list? HOT 1
- IsToday()、IsYesterday()、IsTomorrow()in other timeZone is invaild HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from carbon.