How to change date format within velocity template for release notes?

Kristjan Slomšek
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 1, 2011

Hi,

i am trying to customize release notes view by creating velocity template. I figured mostly everything I needed, only date format is not working properly for me. I am trying to use

$date.format("dd/MMM/yy",$versionObj.releaseDate)

But the only result is that above line literally prints out itself as string and no formated date as one would expect.

What am I doing it wrong?

tnx & brg,

K

3 answers

1 vote
Maximilian Neis January 29, 2016

Five years later . . .

I also had my Problems, as none of the listed classes work for me

https://thepluginpeople.atlassian.net/wiki/display/JEMH/Work+with+Dates+in+velocity+templates

 

But I used the formatter class provided by oracle to do this:

#set( $DateString = '' )##

$DateString.format('%1$tY%1$tm%1$td', $versionObj.releaseDate)

You need to change it a bit to fit on your purpose but this should be easily possible as you can see here:

https://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html

0 votes
mwarton
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 29, 2014

Hi,

I know it's a little late, but if you are looking for an easier way try Intelligent Reports. It lets you design your release notes in Microsoft Word, then fill in the data using simple point and click rules. No scripting or API to learn and debug.

0 votes
m@
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 11, 2011

Velocity is printing out the literal because it can't resolve $date and/or the methods on it.

If you're doing this on JIRA, this page (http://confluence.atlassian.com/display/JIRADEV/Contents+of+the+Velocity+Context) lists all the variables automatically added to the context for your use. You probably want the dateutils variable.

Update: http://docs.atlassian.com/atlassian-core/5.0-SNAPSHOT/apidocs/com/atlassian/core/util/DateUtils.html

Kristjan Slomšek
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 28, 2011

Thank you Matthew for the provided answer.

I have already saw that link on date util, problem is as it is not clear to me, how to include dateutils inside .vm file. I have tried many ways (as doc suggests, but date util object was not included on the final printout).

Can you help me with that (using jira v4.3.3#617-r14961)?

AnaG January 28, 2014

Any news on this subject?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events