Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

calendar.getInstance() or calendar.clone()

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.

like image 953
Aravind Yarram Avatar asked Apr 07 '10 20:04

Aravind Yarram


People also ask

What is Calendar getInstance () in Java?

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.

What does calendar getInstance () getTime () this return?

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


1 Answers

I would use

newTime= (Calendar) originalDate.clone(); 
like image 84
armandino Avatar answered Oct 09 '22 17:10

armandino