issue with dateTool

rajani's Avatar

rajani

10 Feb, 2016 01:42 PM

Hi , i m using velocity -7.jar and velocity-tools-generic-2.0.jar.

I m not able to render the date tool. I am trying all these in my template but not able to get the result. I have tried putting the Product_Date as string(12/12/2007) as well as new Date() . Not working by any possible combination.

$date.toDate("MM-dd-yyyy",$Product_Date);

$date.format( 'full','short', $date.toDate( "EEE, dd MMM yyyy hh:mm:ss Z" , $Product_Date.getData()) )

$date.toDate("EEE, dd MMM yyyy hh:mm:ss Z", $Product_Date)

$date.format($Product_Date) -- I want format API also to work.

Please help..its urgent.. am i using wrong jars?

  1. 1 Posted by Ryan Griffith on 10 Feb, 2016 01:48 PM

    Ryan Griffith's Avatar

    Hi,

    To confirm, are you attempting to do this within a Velocity Format? If so, the Date Tool is accessed using $_DateTool, not $date.

    That being said, there are a few ways to format a date:

    • If the context is already a Date object, you can use $_DateTool.format("FORMAT_STRING", $dateVariable) directly
    • If the context is a unix timestamp, you would first use $_DateTool.getDate($timestampVariable) to convert the timestamp into a Date object. Then you can use $_DateTool.format to format the resulting Date object (see above)
    • If the context is a formatted date string, you would first use $_DateTool.toDate("FORMAT_STRING", $stringVariable) to convert the formatted string into a Date object. Then you can use $_DateTool.format to format the resulting Date object (see above)

    For more information about formatting and available modifiers, see this page.

    Please let me know if you have any questions.

    Thanks!

  2. 2 Posted by rajani on 10 Feb, 2016 02:06 PM

    rajani's Avatar

    Hi,

     I have a javascript code:

     var date1 = new org.apache.velocity.tools.generic.DateTool;
     var date2 = new Date();
        context.put("Product_Date", date2);
        context.put("date", date1);
        context.put("format", format1);
    context.put("sorter", sort);

    then i use the template.merge(). Then trying to render in the template as in the first query.
    Sorter is working fine. But not the format and date.

    so, i m using the $date. Will this not work.

  3. 3 Posted by rajani on 10 Feb, 2016 02:20 PM

    rajani's Avatar

    I tried using _DateTool also.. but still its not working

  4. 4 Posted by Ryan Griffith on 10 Feb, 2016 06:10 PM

    Ryan Griffith's Avatar

    Hi,

    I have a javascript code:

    My apologies, but I am not sure if I am following. Are you writing this code within a Velocity Format, a JavaScript file, or Java? Based on your initial comment, it appears you are working with Velocity; however, based on your latest comment it looks like you are working with Java.

    If you can attach or paste your code as it stands, that may help provide some context as well.

    Thanks!

  5. Support Staff 5 Posted by Tim on 26 Feb, 2016 09:56 PM

    Tim's Avatar

    Hi,

    Just wanted to make sure you saw Ryan's comment above.

    Thanks

  6. Tim closed this discussion on 09 Mar, 2016 04:22 PM.

Discussions are closed to public comments.
If you need help with Cascade CMS please start a new discussion.

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

 

26 Aug, 2016 01:19 PM
25 Aug, 2016 03:02 PM
25 Aug, 2016 12:50 PM
24 Aug, 2016 08:43 PM
24 Aug, 2016 07:20 PM
21 Aug, 2016 01:20 PM