Results 1 to 5 of 5
  1. #1
    valoyivd is offline Member
    Join Date
    Mar 2008
    Posts
    8
    Rep Power
    0

    Default date and calender not getting the right results

    Java Code:
    public class TestDate {
    
        public static void main(String[] args) {
            Calendar calendar = Calendar.getInstance();
            System.out.println("before 30***********" + calendar.get(Calendar.DAY_OF_MONTH));
            calendar.add(Calendar.DAY_OF_MONTH, 30);
            System.out.println("after 30 **********" + calendar.get(Calendar.DAY_OF_MONTH));
            int days = calendar.get(Calendar.DAY_OF_MONTH);
            System.out.println("days*************" + days);
        }
    }

  2. #2
    sanjeevtarar's Avatar
    sanjeevtarar is offline Senior Member
    Join Date
    Apr 2008
    Location
    Jaipur(India)
    Posts
    318
    Rep Power
    7

    Default

    Hello,

    What you want to get?

    calendar.get(Calendar.DAY_OF_MONTH) : It will return day....
    if you want to add or subtract days then you will have to use

    calendar.set(Calendar.DAY_OF_MONTH, 30)

    Please clear you Question..??


    sanjeev

  3. #3
    valoyivd is offline Member
    Join Date
    Mar 2008
    Posts
    8
    Rep Power
    0

    Default

    I want to get the days after adding 30 days....before is suppose to print the current date...and after is suppose to print the days after adding 30 days

  4. #4
    sanjeevtarar's Avatar
    sanjeevtarar is offline Senior Member
    Join Date
    Apr 2008
    Location
    Jaipur(India)
    Posts
    318
    Rep Power
    7

    Default

    See this code...

    Java Code:
    	public static void testDate(){
    		Calendar calendar = Calendar.getInstance();
    		java.util.Date beforDate = calendar.getTime();
    		System.out.println("beforDate : " + beforDate);
    
    		// Adding 30 Days to current Date.
            calendar.add(Calendar.DAY_OF_MONTH, 30);
    		java.util.Date afterDate = calendar.getTime();
    		System.out.println("afterDate : " + afterDate);
    	}


    sanjeev

  5. #5
    valoyivd is offline Member
    Join Date
    Mar 2008
    Posts
    8
    Rep Power
    0

Similar Threads

  1. java.util.Date vs java.sql.Date
    By Jack in forum New To Java
    Replies: 5
    Last Post: 10-28-2010, 02:59 PM
  2. Difference between current date and anothe date
    By vijay balusamy in forum New To Java
    Replies: 1
    Last Post: 04-16-2008, 04:15 PM
  3. Datepicker Calender - month change event - jquery
    By rmpatel101 in forum Advanced Java
    Replies: 0
    Last Post: 04-02-2008, 06:42 PM
  4. BigInteger remainder results in zero
    By perito in forum New To Java
    Replies: 1
    Last Post: 03-21-2008, 04:07 PM
  5. results to code disappear too fast for DOS window
    By dubdubdub in forum New To Java
    Replies: 3
    Last Post: 12-29-2007, 05:07 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
  •