Skip to content

Comparing the Timestamp/date between two given timestamps/dates

June 5, 2010

JavaUsing java.util.Date is quite common and often we are encountered with situations where we want to compare Timestamp. The class hierarchy of Timestamp class is:



The code given below represents a situation where current timestamp (today’s date) is between two given timestamps i.e startDate and endDate.  


public int timeStampCompare(Date today,Date date){
            if (today == date) {
                return 0;
            else if (today.compareTo(date)<0) {
                 return -1;
                return 1;

 Calling the above function

Date today = new Date();// gives us the present date and time

           if (timeStampCompare(today, startDate)!=-1 && timeStampCompare(today, endDate)!=1 ){
               System.out.println(“ I am between the timestamp ”);
               System.out.println(“ Oppss! time is over ”);

From → Java

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: