The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
November 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

You need to use the java.util.GregorianCalendar class

Posted by Don on November 22, 2000 at 7:20 PM

> My problem is the following:
> I need to give a time-to-live to a string on a DB, so what I do is simply to add a period (expressed in days) to the current Date.

Within GregorianCalendar is a method called add(int field, int amount). See the Calendar class for all the different static fields. So an example that adds 2 days to the current time:
GregorianCalendar current = new GregorianCalendar();
System.out.println(current.getTime().toString());
current.add(Calendar.DATE,2);
System.out.println(current.getTime().toString());





Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us