This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
Hey e'body,... It would be Great if anybody can help me with, how I can find the number of Days between two dates.. like for example # days between 08/07/2003 & 09/15/2003 .. Which Class do you suggest me to Use.. ( Date,Calendar,DateFormat ??? how?) Thx a lot for your help.. Appreciate it..
The way I usually do something like that is... SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy"); Date d1 = dateFormat.parse("08/07/2003"); Date d2 = dateFormat.parse("09/15/2003"); long time = d2.getTime() - d1.getTime(); // t dif in ms // then convert time to the time units you want
- Chris Stehno, SCPJ
Joined: Jun 15, 2002
Thanks a lot Chris.. So If you want me to get the # of days ... I think i'll Go this way : long time = d2.getTime() - d1.getTime(); // t dif in ms int days=(int)time/(24*36*100000); I hope this is going to work always.. Let me know, if by chance i'm going wrong somewhere.. Thx anyway