Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , ,

Sponsored Links



Problem calculating date

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 23-02-2010
Member
 
Join Date: Dec 2009
Posts: 296
Problem calculating date

Hello,
I have a problem with a date calculation in fact I have the following code.
Code:
String str = "";

    Integer d = new Integer(d);
    mn = Integer new Integer(months);
    Integer yr = new Integer(years);

    System.out.System.out.println("d"+ d);
    System.out.System.out.println("mn"mn +);
    System.out.System.out.println("yr"+ yr);
    Calendar nwdt = new GregorianCalendar(yr.intValue(),
                                             mn.intValue(),
                                             d.intValue());
    System.out.System.out.println("nwdt"+ nwdt);
    System.out.System.out.println("periodiciteMois" + PeriodiciteMois);
    nwdt.add(Calendar.MONTH, periodiciteMois);

    str = Utilities.makeString(nwdt.get(Calendar.DAY_OF_MONTH),2) + "." +
                                   Utilities.makeString(nwdt.get(Calendar.MONTH),2) + "." +
                                   Utilities.makeString(nwdt.get(Calendar.YEAR),4);

    System.out.System.out.println("str"+ str);
Please check the code, and check if it is correct, if not then please guide me with the correct.
Reply With Quote
  #2  
Old 23-02-2010
Member
 
Join Date: Nov 2009
Posts: 335
Re: Problem calculating date

Hello,
Here is the code for doing the same, please see if this helps you.
Code:
newDate.add(Calendar.DATE, -1);
int mn = newDate.get(Calendar.MONTH); mn + +;
int dy = newDate.get(Calendar.DAY_OF_MONTH);
int yr = newDate.get(Calendar.YEAR);
If this works for me , see if this works for you.
Reply With Quote
  #3  
Old 23-02-2010
Member
 
Join Date: Nov 2009
Posts: 331
Re: Problem calculating date

Hello,
Currently, when I want to do calculations on dates, I create like you:
Code:
Calendar nwdt = new GregorianCalendar(year.intValue(),
                                             month.intValue(),
                                             day.intValue());
Then, if I want the same date in 15 days, I do:
Code:
nwdt.add(Calendar.DATE, 15);
And then I extract the day, month and year of the new date:
Code:
int Month = nwdt.get(Calendar.MONTH); Month + +;
int Day = nwdt.get(Calendar.DAY_OF_MONTH);
int Year = nwdt.get(Calendar.YEAR);
I suggest this, not knowing exactly and functionally what you're looking to do with your dates.
Reply With Quote
  #4  
Old 23-02-2010
Member
 
Join Date: Nov 2009
Posts: 347
Re: Problem calculating date

Hello,
You can try alternatively using the following
Code:
Calendar nwdt = new GregorianCalendar(year.intValue(),
                                             month.intValue()-1,
                                             day.intValue());
And when you want to retrieve the month you adds' +1'. Months are calculated, they go from 0 to 11. I hope you are understanding the things now. If you need any more help then please do post back.
Reply With Quote
  #5  
Old 23-02-2010
Member
 
Join Date: Nov 2009
Posts: 447
Re: Problem calculating date

Hello,
You can try the following code:
Code:
java.text.SimpleDateFormat s = new java.text.SimpleDateFormat("dd.MM.yyyy");
java.util.Calendar nwdt = java.util.Calendar.getInstance();
/ / parse (...) method converts String to java.sql.Date
nwdt.setTime(s.parse("08.12.2004"));
int periodiciteMois = 12;
nwdt.add(java.util.Calendar.MONTH, periodiciteMois);
/ / format (...) method transforms the java.sql.Date to String format jj.mm.yyyy
String = str s.format(nwdt.getTime());
System.out.System.out.println("str"+ str);
Just try it and if you have any more problem then post back with the error you get.
Reply With Quote
  #6  
Old 23-02-2010
Member
 
Join Date: Dec 2009
Posts: 192
Re: Problem calculating date

Hello,
I am new to java but I have a code which may interest you. Have a look at it
Code:
import java.util.*;
public class Now {
   public static void main(String[] args) {
      Date nw = new Date();
      long nwlg = nw.getTime();
      System.out.println("Value is " + nwlg);
   }
}
Hope this will help you and you will solve your problem.
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Problem calculating date"
Thread Thread Starter Forum Replies Last Post
Problem calculating duration in java Gunner 1 Software Development 5 05-02-2010 04:56 AM
Finish Date calculating incorrectly - ignoring Duration Ana Figueira Microsoft Project 4 05-08-2009 02:35 AM
Problem with Php date function HAMAKO Software Development 1 21-04-2009 01:38 PM
Calculating date in Excel MarceloQuad Windows Software 2 16-03-2009 11:56 PM
Fix the damn "Calculating Time Remaining" problem already! IWantXPBack Vista Help 27 20-01-2008 06:32 AM


All times are GMT +5.5. The time now is 07:38 AM.