使用 DateTimeConstants(JodaTime) 值将 dayOfTheWeek 存储在数据库中?

发布于 2024-10-25 22:24:17 字数 224 浏览 4 评论 0原文

我需要将 dayOfTheWeek 存储在数据库的列中。我使用 HSQLDB。另外,我已经将 JodaTime 用于其他类型,例如时间戳。 我正在考虑将 int 或 string 值封装到一个类中,因此 JodaTIme 已经为常量、星期一、星期二、星期三等提供了 int 值...

这是一个好主意还是坏主意?就像 JodaTime 决定更改天数的值一样 或者我应该存储不同的东西?就像创建我自己的枚举一样......

I need to store a dayOfTheWeek in a column of my database. Im using HSQLDB. Also, Im already using JodaTime for other types, like Timestamp.
Im thinking about encapsulate the int or string values into a class, so JodaTIme has already int values for the Constants, Monday, Tuesday, Wednesday, etc...

Is this a good or bad idea? Like if somewhat JodaTime decides to change the values for the days
Or should I store something different? Like creating my own enum...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最终幸福 2024-11-01 22:24:17

星期几的 int 值由 ISO-8601 定义,并且不会更改。因此,它们可以安全地存储在数据库中。如果您想更进一步,您可以创建一个枚举/类来包装该值,但我认为这并没有真正为 Joda-Time 增加价值(JSR-310/ThreeTen 有一个 DayOfWeek 枚举)。

The int values for day-of-week are defined by ISO-8601 and won't be changing. As such, they are safe to store in a database. If you want to go further, you could create an enum/class to wrap the value, but I don't think that is really adding value with Joda-Time (JSR-310/ThreeTen has a DayOfWeek enum).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文