Du bist hier: Snippet-Verzeichnis » Java (241)
Sprache:

Adding days to a Date

Sprache: English
Programmiersprache: Java
Veröffentlicht von: getprabhu [nicht registriert]
Letzte Änderung: 15.05.2006
Aufrufe: 1426


Beschreibung

This sniipet of method tells u how to get a new Date with the specified number of days added to the existing Date

Code

1 public java.util.Date addMonthstoDate(java.util.Date dtnDate, 2 int intNoOfMonths throws Exception{ 3 try { 4 java.util.Date dtnCalcNewDate = null; 5 GregorianCalendar cal = new GregorianCalendar(); 6 cal.setTime(dtnDate); 7 cal.add(Calendar.MONTH,intNoOfMonths); 8 dtnCalcNewDate = cal.getTime(); 9 return(dtnCalcNewDate); 10 }catch (Exception e) { 11 throw e; 12 } 13 }

Ein Kommentar

1

Hi,

the description says that there will be days added. In by opinion, where are month added.

I have tested the snipplet in a little program and my result is, that here are month added through the specified constant Calendar.MONTH.

If you use the constant Calendar.DAY_OF_MONTH you can add days.

Freitag, 25. August 2006 21:52:39 von Der Informatik Student

Dieses Snippet kommentieren

Name *  

E-Mail (wird nicht angezeigt) *    

Website  

Kommentar *  

Sicherheitscode Sicherheitscode *    

RSS