Commons Lang
  1. Commons Lang
  2. LANG-194

[lang] add generic add method to DateUtils

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.2
    • Component/s: None
    • Labels:
      None
    • Environment:

      Operating System: Windows XP
      Platform: PC

      Description

      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(); }

        Activity

        Hide
        Henri Yandell added a comment -

        Calendar.getInstance() rather than new GregorianCalendar.

        Show
        Henri Yandell added a comment - Calendar.getInstance() rather than new GregorianCalendar.
        Hide
        Stephen Colebourne added a comment -

        Implemented in svn 394553

        Show
        Stephen Colebourne added a comment - Implemented in svn 394553
        Hide
        Henri Yandell added a comment -

        Reopening then closing to deal with migration bug.

        Show
        Henri Yandell added a comment - Reopening then closing to deal with migration bug.
        Hide
        Henri Yandell added a comment -

        Reopening then closing to deal with migration bug.

        Show
        Henri Yandell added a comment - Reopening then closing to deal with migration bug.

          People

          • Assignee:
            Unassigned
            Reporter:
            David Bowers
          • Votes:
            1 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development