Solved

date function in jsp

Posted on 2004-03-23
3
953 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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 …

831 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