I need to make a copy of a given date 100s of times (I cannot pass-by-reference). I am wondering which of the below two are better options
newTime=Calendar.getInstance().setTime(originalDate);
OR
newTime=originalDate.clone();
Performance is of main conern here.
thx.
The getInstance() method in Calendar class is used to get a calendar using the current time zone and locale of the system. Syntax: public static Calendar getInstance() Parameters: The method does not take any parameters. Return Value: The method returns the calendar.
Calendar. getInstance(). getTime() : Returns a Date object representing this Calendar's time value (millisecond offset from the Epoch(January 1, 1970 00:00:00.000 GMT (Gregorian).)
I would use
newTime= (Calendar) originalDate.clone();
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