一周内的时间点
有没有一种简单的方法来存储相对于一周中的几天的时间点,而不是 Java 中的确切日期(例如,星期一晚上 11:00,而不是 2011 年 5 月 23 日星期一晚上 11:00)?
当然,与另一个给定的“完整”日期和时间进行比较是一个很好的功能,这样我就可以确定它是否“等于”上述时间点(例如星期一晚上 11:00 等于2011 年 5 月 23 日星期一晚上 11:00)。
Is there a simple way to store points of time relative to days of a week and not an exact date in Java (e.g. Monday 11:00 pm instead of Monday, May 23st 2011, 11:00 pm)?
Of course it would be a nice feature to have a comparision with another given "complete" date and time, so that I can determine if it is "equal" to the point of time mentioned above (e.g. Monday 11:00 pm is equal to Monday, May 23st 2011, 11:00 pm).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议您查看 Joda time 开源库。它没有任何开箱即用的东西可以完全满足您的要求,但您应该能够为 Partial 类编写自定义扩展来跟踪一周中的一天和时间。
I would recommend checking out the Joda time open source library. It doesn't have anything right out of the box that does exactly what you want, but you should be able to write a custom extension to the Partial class that tracks a day of week and time.
我不知道是否有内置的东西可以做到这一点,但构建自己的应该不会太难。
既然日期并不重要,那么设置一个恒定的日期作为起点并且时间与该点相关怎么样?只需删除实际日期以供显示即可。这样,所有内置日期计算都能正确进行。
您可以(应该)将行为封装在一个类中,以便存储完整日期这一事实是一个实现细节。
I don't know if there's anything built in to do that, but it shouldn't be too hard to build your own.
Since the date doesn't matter, how about setting a constant date as a starting point and the times will be relevant to that point? Just drop the actual date for display purposes. That way all the build-in date calculations work out correctly.
You can (should) encapsulate the behavior in a class, so that the fact that a full date is stored is an implementation detail.