Created
April 16, 2013 16:20
-
-
Save cfalzone/5397317 to your computer and use it in GitHub Desktop.
Getting the number of days in the month in Velocity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## Get a Date object for today | |
| #set($today = $date.getDate()) | |
| ## Get a Calendar Object | |
| #set($cal = $date.getCalendar()) | |
| ## Set the Calendar Object to today | |
| #set($_x = $cal.setTime($today)) | |
| ##get the number of days in the month: | |
| #set($days = $cal.getActualMaximum(5)) | |
| ## Note: 5 corresponds to Calendar.DATE: | |
| ## http://docs.oracle.com/javase/6/docs/api/constant-values.html#java.util.Calendar.DATE | |
| <p>There are $days days in this ${date.format('MMMM yyyy', $today)}.</p> | |
| #set($aDate = $date.toDate("yyyy-MM-dd","2014-02-01")) | |
| #set($_x = $cal.setTime($aDate)) | |
| #set($days = $cal.getActualMaximum(5)) | |
| <p>There are $days days in ${date.format('MMMM yyyy', $aDate)}.</p> | |
| #set($bDate = $date.toDate("yyyy-MM-dd","2012-02-01")) | |
| #set($_x = $cal.setTime($bDate)) | |
| #set($days = $cal.getActualMaximum(5)) | |
| <p>There are $days days in ${date.format('MMMM yyyy', $bDate)}.</p> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment