Is there a date formater that takes into account the timezone?

Ioan Damian
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!
October 6, 2011
When creating an issue with 2 custom fields of type "Date Time" the date is saved in UTC format. The notification doesn't take into account the timezone displaying the time and date in UTC format.
We've created a new file named customFieldFrom.vm in /opt/jira/atlassian-jira/WEB-INF/classes/templates/email/html/includes/fields with the following content:
#if ($issue.getCustomFieldValue("customfield_10040"))
<tr valign="top">
    <td style="color:${textColour};font-family:${textFontFamily};font-size:${textSize};padding:0 10px 10px 0;white-space:nowrap;">
    <!--
        -->
        <strong style="font-weight:normal;color:${textSubtleColour};">From:</strong>
    </td>
    <td style="color:${textColour};font-family:${textFontFamily};font-size:${textSize};padding:0 0 10px 0;width:100%;">
        $dateformatter.formatDMYHMS($issue.getCustomFieldValue("customfield_10040"))
    </td>
</tr>
#end
In /opt/jira/atlassian-jira/WEB-INF/classes/templates/email/html/issuecreated.vm we've added the following line:
#parse("templates/email/html/includes/fields/customFieldFrom.vm")
 
Our problem is the function $dateformatter.formatDMYHMS($issue.getCustomFieldValue("customfield_10040")) retrieves the UTC time. We need a function that also takes into account the timezone for the user that created the issue.
Any help would be highly appreciated. Thank you in advance

1 answer

0 votes
Andriy Zhdanov
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.
May 17, 2012
TimeZone timezone = timeZoneManager.getLoggedInUserTimeZone();
params.put("outlookDate", dateTimeFormatterFactory.formatter().withStyle(DateTimeStyle.DATE).forLoggedInUser().withZone(timezone));

.... in vm:

$outlookDate.format(YOUR_DATE)

Suggest an answer

Log in or Sign up to answer