You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by bu...@apache.org on 2005/01/14 18:23:40 UTC

DO NOT REPLY [Bug 33102] New: - add generic add method to DateUtils

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=33102>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=33102

           Summary: add generic add method to DateUtils
           Product: Commons
           Version: unspecified
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Lang
        AssignedTo: commons-dev@jakarta.apache.org
        ReportedBy: vive_lafrique@yahoo.com


There is no way to do Date arithmetic in one line in Java, unless you use
deprecated methods.  The following method initializes a Calendar object with a
date and performs date arithmetic on it, and returns the result as a java.util.Date.

  public static Date add(Date date, int field, int amount) {
    Calendar c = new GregorianCalendar();
    c.setTime(date);
    c.add(field, amount);
    return c.getTime();
  }

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org