The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results forĀ 
Search instead forĀ 
Did you mean:Ā 

How can I get the current date as a formatted string in a User Macro?

Jeremiah Dost
August 28, 2023

I am trying to get the current date for a user macro. I've tried using various utilities that documentation seems to indicate will be available, but to no avail. These include Java's, VTL's, and Confluence specific VTL context (https://developer.atlassian.com/server/confluence/confluence-objects-accessible-from-velocity/). 

 

For example, I'd expect to be able to do something like this:

#set ($dateString = $date.get('yyyy-MM-dd') )

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
Answer accepted
Sayed Bares [ServiceRocket]
Community Champion
August 29, 2023

@Jeremiah Dost can you give this a try:

#set ($dateString = $action.dateFormatter.formatGivenString("yyyy-MM-dd",$content.currentDate))
Jeremiah Dost
August 29, 2023

I ended up finding a solution later last night where I used a Calendar in conjunction with the .formatGivenString() method you have here.

#set ($today = $action.dateFormatter.formatGivenString("yyyy-MM-dd", $action.dateFormatter.getCalendar().getTime()) )

I don't see a currentDate field in the documentation for the ContentEntityObject (https://docs.atlassian.com/atlassian-confluence/6.6.0/index.html?com/atlassian/confluence/core/ContentEntityObject.html), but I'll give it a try.

Like • Sayed Bares [ServiceRocket] likes this
Jeremiah Dost
August 29, 2023

That worked! Thank you, Sayed.

Like • Sayed Bares [ServiceRocket] likes this
TAGS
AUG Leaders

Atlassian Community Events