• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

initialise & add date

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hihi.. how can i do a initialzation of date to 2nd June 2005, then add 3 days of the last date value? below is a sample of my code.

import java.util.Date;

public class Calendar {
private static Date today;

public static Date getDate() {
return (Date)today.clone();
}

public static void tock(int days) {
//add advance date (7 days)???
}
}
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I won't post code here, you can figure it out by looking at the SimpleDateFormat class.
Another thing, avoid to call your class "Calendar", because it's already an Java API class.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes, I think you can use these apis and codes:
apis:
SimpleDataformat
java.util.GregorianCalendar.

codes:
.....

public Date getTheAfterDay(Date date, int days) {
GregorianCalendar startCalendar = new GregorianCalendar();
startCalendar.setTime(date);
startCalendar.add(GregorianCalendar.DATE, days);
return startCalendar.getTime();
}

You need import java.util.Date and java.util.GregorianCalendar .
Good Luck!
if you have any qustions please contact me , my msn :wp_java_wp@hotmail.com
 
reply
    Bookmark Topic Watch Topic
  • New Topic