...
- Understand the related Java classes
java.util.Date
java.util.Locale
java.util.TimeZone
java.util.Calendar
andorg.ofbiz.base.util.UtilDateTime
- Avoid making assumptions
- Never use millisecond arithmetic
Also long ago Adrian suggested this 3 rules/use-cases which make much sense and helps to understand, more could be added...
- Automatic server processes like the Job Scheduler should use the server's timezone.
- Customer-facing processes should use a product store's timezone. Example: "Your order will be shipped by 4:30 PM PST today."
- Calendar applications (anything work effort related) should use the user-selected timezone.
The java.util.*
Classes
The java.util.Date
class, and its subclass java.sql.Timestamp
should be thought of as a constant. It is an immutable moment of time occurring in GMT. (The Date
class has setXxxx methods, but they are all deprecated.) You cannot change a Date
's time zone - it is, and always will be, referenced to GMT.
...
Knowing that the Date
class wraps a millisecond value makes it tempting to use millisecond arithmetic to perform date/time calculations. That approach will always fail - because it doesn't take into consideration different calendar systems, time zones, etc. OFBiz developers should never use millisecond arithmetic.