|
| |||||||||
| Tags: calculating classes, calendar class, date, javautil, utiltities |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| 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); |
|
#2
| |||
| |||
| 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); |
|
#3
| |||
| |||
| 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()); Code: nwdt.add(Calendar.DATE, 15); Code: int Month = nwdt.get(Calendar.MONTH); Month + +; int Day = nwdt.get(Calendar.DAY_OF_MONTH); int Year = nwdt.get(Calendar.YEAR); |
|
#4
| |||
| |||
| Re: Problem calculating date
Hello, You can try alternatively using the following Code: Calendar nwdt = new GregorianCalendar(year.intValue(),
month.intValue()-1,
day.intValue()); |
|
#5
| |||
| |||
| 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); |
|
#6
| |||
| |||
| 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);
}
} |
![]() |
|
| Thread Tools | Search this Thread |
| |
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 |