Re: Getting Date Difference in Java.
- From: Christophe Tela <c.tela_at_no@xxxxxxxxxxxx>
- Date: Sat, 07 May 2005 22:42:46 +0200
> 1. How do I get the date in java in a specific format (in any format I
> choose). What is the best object for this.
Look at the SimpleDateFormat class.
> 2. How do I get the difference in 2 dates, which should give me in number
> of days.
Look at Calendar.getTimeInMillis() method. It provides a number of
milliseconds since January 1, 1970.
You should code something like :
static int MILLIS_IN_DAY = 1000 * 60 * 60 * 24;
int diffInMillis = cal1.getTimeInMillis() - cal2.getTimeInMillis();
double diffInDays = diffInMillis / MILLIS_IN_DAY;
HTH,
Christophe
.
- Follow-Ups:
- Re: Getting Date Difference in Java.
- From: Ernst-Udo Wallenborn
- Re: Getting Date Difference in Java.
- References:
- Getting Date Difference in Java.
- From: Lucky
- Getting Date Difference in Java.
- Prev by Date: Re: Database Query Tool
- Next by Date: Re: Boolean as argument to a stored procedure not working with JDBC
- Previous by thread: Getting Date Difference in Java.
- Next by thread: Re: Getting Date Difference in Java.
- Index(es):
Relevant Pages
|