Calculated text field format date

Roy Chapman August 13, 2018

Hopefully a simple question.  A user wants to "hide" date fields on a tab (rather than them appearing in the date section.  The only way I can do this is to maintain a matching calculated text field that takes a copy of the date each time it changes, like this

if (issue.get("customfield_13503") != null)  return issue.get("customfield_13503");

I then remove the actual date fields from the view screen.  Only problem is the format of the date field appears as 

"2018-08-13 00:00:00.0"

Any way of formatting this?

1 answer

1 accepted

1 vote
Answer accepted
David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 13, 2018

Hi Roy,

there are multiple ways to format the date according to your needs, such as:

if (issue.get("customfield_13503") == null)
  return null;
return issue.get("customfield_13503").toLocaleString();

or to use Jira's default formatting:

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.datetime.DateTimeFormatter;
import com.atlassian.jira.datetime.DateTimeStyle;

if (issue.get("customfield_13503") == null)
return null;

DateTimeFormatter dtf = ComponentAccessor.getComponent(DateTimeFormatter.class);
return dtf.withStyle(DateTimeStyle.DATE).format(issue.get("customfield_13503"));

and you can change the date time style using one of the constants here: https://docs.atlassian.com/software/jira/docs/api/7.2.9/com/atlassian/jira/datetime/DateTimeStyle.html

Roy Chapman August 13, 2018

Awesome!  thanks for the quick response.  Exactly what I was looking for

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events