Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

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

0 votes
Answer accepted
Sayed Bares [ServiceRocket]
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 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.

Jeremiah Dost August 29, 2023

That worked! Thank you, Sayed.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Upcoming Confluence Events