Take the 2-minute tour ×

I have a legacy Java application, where its performance bottle neck is due to the usage of Calendar. As Calendar is a mutable object, we have to clone every-time we get it.

public Calendar getCalendar() {
    return (Calendar)calendar.clone();

We also discover that in our application, we didn't use the time zone information at all. I was wondering, should we just re-factor the code to

public long getTimestamp() {
    return timestamp;

We will only turn the timestamp into Calendar or Joda DateTime, when we need to perform date/time arithmetic operation.

Or to prevent unforeseen future, should we use Joda DateTime?

public DateTime getDateTime() {
    return dateTime;
share|improve this question
LocalDateTime is the suitable class to use, not DateTime, if you do not have time zone info to store –  JodaStephen Nov 9 '10 at 8:48
@JodaStephen, I was wondering if in the future, I need TimeZone information, is the change will be cheap? (That's why I hesitate to use pure 'long'). If I just don't need time zone info, I will instead choose to use 'long', and use Java Calendar whenever there is arithmetic or comparison need. –  Cheok Yan Cheng Nov 11 '10 at 2:05
add comment

2 Answers

Generally, if you don't care about timezone and you have to store a lot of timestamps, you'd better store them as long-s. It is 8 bytes per timestamp. All object oriented date-time wrappers around 'long' will consume at least 24 bytes per timestamp. When you'll need to perform any datetime arithmetic - convert your long timestamp into a Joda DateTime (or MutableDateTime). They are both implemented as wrappers around a 'long' field, so creating them from long is extremely cheap.

share|improve this answer
You mean as a long right? What do you mean by long-s? (Oh, I think you mean longs.) –  David James Jul 26 '13 at 5:04
See also: joda-time.sourceforge.net/faq.html#long –  David James Jul 26 '13 at 5:16
add comment

You should definitely use JodaTime. Make sure you pass around your dates in java.util.Date, which is just a long number of milliseconds since 1/1/1970 in UTC.

share|improve this answer
add comment

Your Answer


