CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 1999
    Posts
    1

    How to calculate given date in calendar

    Hi,

    I am just starting to learn Java by myself and now really don't know how to solve my problem.
    I have problem in how to calculate calendar. For example, for any given date and given the N date you can calculate the new date.

    Please help.

    Thanks very much




  2. #2
    Join Date
    Sep 1999
    Location
    Madurai , TamilNadu , INDIA
    Posts
    1,024

    Re: How to calculate given date in calendar


    one solution is :


    // Adding 10 days with the current date.

    Calendar cal = Calendar.getInstance();
    cal.set( Calendar.DATE , cal.get( Calendar.DATE ) +10 );





    Another solution with the Date class is :



    // Calculate milliseconds for current date and add milliseconds for 10 days with it.
    Date d = new Date();
    long nSeconds = d.getTime() + ( 10 * 24 * 60 * 60 * 1000 );
    d.setTime(nSeconds);





    But i am getting weird result when i tried to add 30 days with the current date in Date
    class. I dont have time to research on it.

    Poochi..



Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured