Results 1 to 6 of 6

Thread: Exactly match date in java

  1. #1
    Join Date
    Dec 2009
    Posts
    192

    Exactly match date in java

    Hello,
    I am trying a code in java and I want to do the following test if
    Code:
    (Date.getDay () = Sunday)
    but because the method returns an int getDay I wanted to know the code on Sunday to an int? Do you have a solution for this , how to convert the integer to a string so that I can use it to compare it with the system date. In short I want to match the date with the system date. Thanks in advance.

  2. #2
    Join Date
    Nov 2009
    Posts
    343

    Re: Exactly match date in java

    Hello,
    Instead uses the Calendar object. Here is an example of use:
    Code:
    		GregorianCalendar td = new GregorianCalendar();
    td.setTimeInMillis( System.currentTimeMillis() );
    
    System.out.System.out.println("Day" + td.get( Calendar.Day_of_week ));
    System.out.System.out.println("Month" + td.get( Calendar.MONTH ));
    
    System.out.System.out.println("Day" + Calendar.TUESDAY );
    System.out.System.out.println("Month" + Calendar.NOVEMBER );

  3. #3
    Join Date
    Nov 2009
    Posts
    333

    Re: Exactly match date in java

    Hello,
    For example, there 31 days in January after 30 then move to January 31 it is correct. Otherwise at this point, this is not the day of the week you are interested, but the day of the month ie DAY_OF_MONTH. I strongly advise you to take a look at the javadoc for the purpose Calendar. Just use the following code in your code and try if it works or else post back with the error you are getting.

  4. #4
    Join Date
    Dec 2009
    Posts
    192

    Re: Exactly match date in java

    Hello,
    I already looked CALENDAR class, but what I want some thing overall, I want to retrieve the last day of the month for any month, months ago or last day is 28 (February) months or is the other 30 or 31 is, I'm not going to do this for every month, there is certainly a method that gives the last day of a month. I was wondering if there is something like last_day_of_month. In addition I am forced to use the Date class and not Calendar.

  5. #5
    Join Date
    Nov 2009
    Posts
    356

    Re: Exactly match date in java

    Hello,
    Method getActualMaximum (Calendar.DAY_OF_MONTH) is for. Then it be enough just to do a set with the least number that interests. Incidentally Calendar goes hand in hand with the Date class. Do what you want only with the Date class is a heresy and incidentally to make ultra-heavy. In general it is better to intelligently work around a problem trying to solve it brutally.

  6. #6
    Join Date
    Nov 2009
    Posts
    518

    Re: Exactly match date in java

    Hello,
    As it is described above the, I have code for it, the code may help you. Here is the code for this. Check it out
    Code:
    Calendar c = Calendar.getInstance();
    Date d = new Date();
    c.setTime(d);
    c.add(Calendar.DATE, 1);
    
    Date d2 = c.getTime();

Similar Threads

  1. Task Start Date does not match constraint
    By ctslaton in forum Microsoft Project
    Replies: 2
    Last Post: 17-09-2011, 04:57 AM
  2. Query with Date in java
    By Gunner 1 in forum Software Development
    Replies: 5
    Last Post: 12-02-2010, 03:55 AM
  3. Find date in java
    By Allan.d in forum Software Development
    Replies: 3
    Last Post: 09-12-2009, 10:43 AM
  4. How to do the Date comparison in Java
    By Rock Villa in forum Windows Software
    Replies: 3
    Last Post: 06-08-2009, 09:44 AM
  5. How to match the most recent date with the project
    By Elsie in forum Software Development
    Replies: 5
    Last Post: 04-05-2009, 12:03 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,715,275,147.28243 seconds with 17 queries