spa
spa

Reputation: 5185

Point of time in a week

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).

Upvotes: 1

Views: 96

Answers (2)

Mike Deck
Mike Deck

Reputation: 18397

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.

Upvotes: 3

David Ly
David Ly

Reputation: 31586

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.

Upvotes: 2

Related Questions