Since Joda-Time time version 2.0 the static method org.joda.time.DateTime#now()
was introduced.
To me it is not clear what is the benefit over the use of new DateTime()
(as the code just delegates anyway).
public static DateTime now() {
return new DateTime();
}
Also from the java doc it is not clear to me which one I should prefer.
new DateTime
Obtains a {@code DateTime} set to the current system millisecond time using
ISOChronology
in the default time zone.
DateTime#now()
Constructs an instance set to the current system millisecond time using
ISOChronology
in the default time zone.
Can someone explain in which use case which one should be preferred?
new DateTime()
requires that a new object be allocated. DateTime.now
can reuse a single object across requests, since DateTime
instances are immutable. That may cause less memory churn.
But largely I doubt it matters which you use.
The now()
method was added to make Joda-Time a little bit closer to java.time.*
in Java 8, making the process of conversion a little bit easier. The two methods have exactly the same behaviour.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With