Results 1 to 4 of 4

Thread: comparing dates

  1. #1
    palls is offline Member
    Join Date
    Aug 2010
    Posts
    1
    Rep Power
    0

    Default 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.");

    }

    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Hello and welcome to the forum. Please tell us what's your specific question? And this doesn't count:
    rectify errors and run the prog (output)
    as that's an assignment instruction.

    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 01:59 PM.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default

    Quote Originally Posted by palls View Post
    rectify errors and run the prog (output)
    Sure thing. Right after you wash my car.

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Darryl.Burke View Post
    Sure thing. Right after you wash my car.
    The gray Ford on the left is my car; it desperately needs to be cleaned first, thank you.

    kind regards,

    Jos ;-)

Similar Threads

  1. UTC Dates
    By PedroCosta in forum Advanced Java
    Replies: 3
    Last Post: 04-01-2010, 07:08 PM
  2. Adding dates how can i do that
    By kirtichopra2003 in forum Advanced Java
    Replies: 7
    Last Post: 10-12-2009, 12:27 PM
  3. Help with dates
    By bumblyb33 in forum New To Java
    Replies: 1
    Last Post: 02-13-2009, 03:54 PM
  4. How to Compare two Dates
    By Java Tip in forum java.util
    Replies: 1
    Last Post: 06-24-2008, 08:05 AM
  5. Comparing dates
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-28-2008, 10:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •