Results 1 to 4 of 4
Thread: comparing dates
- 08-13-2010, 12:46 PM #1
Member
- Join Date
- Aug 2010
- Posts
- 1
- Rep Power
- 0
comparing dates
rectify errors and run the prog (output)
import java.util.*;
import java.text.*;
public class CompareDate
{
public static void main(String args[])
{
Calendar cal = Calendar.getInstance();
Calendar currentcal = Calendar.getInstance();
cal.set(2000, Calendar.JUNE, 29);
SimpleDateFormat sdf =new SimpleDateFormat("dd/MM/yyyy");
currentcal.set(currentcal.get(Calendar.YEAR),curre ntcal.get(Calendar.MONTH), currentcal.get(Calendar.DAY_OF_MONTH));
if(cal.before(currentcal)){
System.out.println("Current date("+ new SimpleDateFormat("dd/MM/yyyy").format(currentcal.getTime())+")is greater than the given date " + new SimpleDateFormat("dd/MM/yyyy").format(cal.getTime()));
}
else if(cal.after(currentcal)){
System.out.println("Current date("+ new SimpleDateFormat("dd/MM/yyyy").format(currentcal.getTime())+") is less than the given date "+ new SimpleDateFormat("dd/MM/yyyy").format(cal.getTime()));
}
else
System.out.println("Both date are equal.");
}
}
-
Hello and welcome to the forum. Please tell us what's your specific question? And this doesn't count:
as that's an assignment instruction.rectify errors and run the prog (output)
Rather, you need to tell us in words what is tripping you up, what is not happening that you expect to happen and visa versa. You may wish to read through the 2nd link in my signature links for more tips on how to ask answerable questions. That link has helped me many times in the past and should help you too.
Also, when posting code here, please use code tags so that your code will retain its formatting and thus will be readable -- after all, your goal is to get as many people to read your post and understand your code as possible, right?
To do this, highlight your pasted code (please be sure that it is already formatted when you paste it into the forum; the code tags don't magically format unformatted code) and then press the code button, and your code will have tags.
Another way to do this is to manually place the tags into your code by placing the tag [code] above your pasted code and the tag [/code] below your pasted code like so:
Java Code:[code] // your code goes here // notice how the top and bottom tags are different [/code]
Luck and again welcome.Last edited by Fubarable; 08-13-2010 at 12:59 PM.
- 08-13-2010, 01:06 PM #3
- 08-13-2010, 01:08 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,602
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
UTC Dates
By PedroCosta in forum Advanced JavaReplies: 3Last Post: 04-01-2010, 06:08 PM -
Adding dates how can i do that
By kirtichopra2003 in forum Advanced JavaReplies: 7Last Post: 10-12-2009, 11:27 AM -
Help with dates
By bumblyb33 in forum New To JavaReplies: 1Last Post: 02-13-2009, 02:54 PM -
How to Compare two Dates
By Java Tip in forum java.utilReplies: 1Last Post: 06-24-2008, 07:05 AM -
Comparing dates
By Java Tip in forum Java TipReplies: 0Last Post: 01-28-2008, 09:02 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks