Thursday, May 22, 2008

Shotest way to determine if a date is within the current month

Note to self:

How to determine a given date is within the current month.


def prevMonth = new GregorianCalendar()
prevMonth.roll(Calendar.MONTH, -1)

def nextMonth = new GregorianCalendar()
nextMonth.roll(Calendar.MONTH, 1)

if (update.after(prevMonth) && update.before(nextMonth)) {
// println "Within this month"
}

This is in Groovy, but can easily be translated to Java.

No comments: