Date object deprecations in Java 1.5 migrating to Calendar object

walshcj's Avatar

walshcj

28 Oct, 2010 03:39 PM

Will Cascade server be providing access to the Calendar object if there is a move to Java 1.6? Our site is currently using Date object methods to reformat dates, and we're beginning to notice a lot of the methods available in the Date object. Our main concern is still have access to these methods, that have mograted to the Calendar object as of Java 1.5

  1. 1 Posted by Brent Arrington on 28 Oct, 2010 07:18 PM

    Brent Arrington's Avatar

    You can access an instance of a Calendar object in either Java 1.5 or 1.6 in Cascade currently, via $_DateTool.getCalendar(). This will return a Calendar instance preset with the current system date/time. You may then use any of the Calendar get/set/add/etc methods.

    One note, however: I know of no way to access the static constant values in Calendar (if anyone out there has managed this, please let me know). So, this code will not work:

        #set ( $calendar = $_DateTool.getCalendar() ) 
    
        ## this will not work
        $calendar.add($calendar.MONTH,1)
    
        ## nor will this -- in fact, this will not compile
        $calendar.add(java.util.Calendar.MONTH,1)
    
    
        #set ( $nextMonth = $calendar.getTime() ) 
    
        Next Month = ${nextMonth}<br/>

    However, the following will work:

        #set ( $calendar = $_DateTool.getCalendar() ) 
    
        ## this WILL work -- 2 is the literal value for java.util.Calendar.MONTH
        $calendar.add(2,1)      
    
        #set ( $nextMonth = $calendar.getTime() ) 
    
        Next Month = ${nextMonth}<br/>

    You can find a list of all the constant values for Calendar here

  2. 2 Posted by Brent Arrington on 28 Oct, 2010 07:22 PM

    Brent Arrington's Avatar

    Oh, incidentally, I was assuming you meant accessing Calendar from Velocity formats in Cascade... Upon a second reading, I can see that might not be what you were asking...

  3. 3 Posted by walshcj on 02 Nov, 2010 09:37 PM

    walshcj's Avatar

    No, that is exactly what I was looking for, thank you.

  4. Tim closed this discussion on 04 Nov, 2010 04:45 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac