Solved

date function in jsp

Posted on 2004-03-23
3
951 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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
A short article about problems I had with the new location API and permissions in Marshmallow
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 …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now