Solved

date function in jsp

Posted on 2004-03-23
3
955 Views
Last Modified: 2008-01-09
how to write date function injsp
can u pls send me code for checking date .
i.e date diffrence should not be greater then 3 days.
pls its urgent
0
Comment
Question by:sameerasawant
3 Comments
 
LVL 3

Accepted Solution

by:
yasser_helmy earned 60 total points
ID: 10659899
Since you said jsp.. i ll assume you are talking about the java part, not the html part..
you can use the java.util.Calendar and java.util.Date classes for date handling..

Calendar c1 = Calendar.getInstance(); //current date
Calendar c2 = Calendar.getInstance(); //other date

c2.set(2004, 02, 23); //set date to 23 april 2004
                               // as the month is 0-based
Date d1= c1.getTime(); //get Date object for c1
Date d2 = c2.getTime(); //get Date object for c2

long millis1 = d1.getTime();  //get number of millis
long millis2 = d2.getTime();  //get number of millis

long diff = millis1 - millis2; //difference between the dates in millseconds
if (diff > 3*24*60*60*1000) { //difference does not exceed 3 days
   //add code here
} else {
   //add code here
}
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question