Results 1 to 4 of 4
  1. #1
    wdh321 is offline Senior Member
    Join Date
    Aug 2011
    Posts
    116
    Rep Power
    0

    Default java calendar and date stamp

    Ive made an ID Card class which has a subclass VisitorIDCard. I want the VisitorIDCard to only be valid for a specific day and then i will check that date with the current date to check if the card is valid or has expired.
    Ive been looking into calendar and simpledateformat but cant seem to work out how i would assign the card a specific date and then how i could check it.

    Any help would be great

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,830
    Rep Power
    19

    Default Re: java calendar and date stamp

    If it's only valid for a specific day then it would probably be easiest to use an 8 character String in the form 'YYYYMMdd' then simply check whether the current date (using SimpleDateFormat to format it into that, um, format) equals() that or not.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    wdh321 is offline Senior Member
    Join Date
    Aug 2011
    Posts
    116
    Rep Power
    0

    Default Re: java calendar and date stamp

    Thanks "Tolls" code is working now. Below is the method i used.

    Java Code:
    public void isValid()
        {
            Calendar cal = Calendar.getInstance();
            SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
            if(sdf.format(cal.getTime()).equals(dateValid))
            {
                System.out.println("Visitor ID Card is Valid");
            }
            else
                System.out.println("Visitor ID Card is not valid");
        }
    Last edited by wdh321; 03-08-2012 at 09:29 PM.

  4. #4
    wdh321 is offline Senior Member
    Join Date
    Aug 2011
    Posts
    116
    Rep Power
    0

    Default Re: java calendar and date stamp

    Ignore this, i just could'nt work out that march was the 3rd month
    Code works now
    Last edited by wdh321; 03-08-2012 at 09:29 PM.

Similar Threads

  1. date limit Java calendar GUI
    By cuti in forum New To Java
    Replies: 4
    Last Post: 01-20-2012, 11:13 PM
  2. Manually setting a date using Calendar and Date
    By ravl13 in forum New To Java
    Replies: 3
    Last Post: 10-25-2011, 11:12 PM
  3. Creating a Gregorian Calendar using a Date object gives date - 1
    By prachi_goliwadekar in forum New To Java
    Replies: 1
    Last Post: 05-08-2008, 08:32 PM
  4. java Date and Calendar
    By valoyivd in forum New To Java
    Replies: 1
    Last Post: 03-30-2008, 06:49 PM
  5. Calendar.DATE
    By mew in forum New To Java
    Replies: 1
    Last Post: 01-04-2008, 07:51 PM

Posting Permissions

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