Hi
I'm trying to create a specific Date in a Confluence user-macro:
#set($dateString = "2025-01-01")
#set($dateFormat = $action.getDateFormat("yyyy-MM-dd"))
#set($date = $dateFormat.parse($dateString))
<p>date: $date .getTime()</p>
#set( $currentDate = $action.dateFormatter.getCalendar())
<p>currentDate: $currentDate.getTime()</p>
gives the following output:
date: $date.getTime()
currentDate: Thu Aug 14 08:43:04 UTC 2025
why is the 1st block with a "custom" date not working?
i also tried this:
#set($newDate = $action.dateFormatter.getCalendar().Builder().setDate(2025,1,1).build())
<p>newDate: $newDate.getTime()</p>
but this doesn't work neither:
newDate: $newDate.getTime()
Hi @Adrian Gaberell ,
dateFormatter that you are trying to use has the following methods https://docs.atlassian.com/atlassian-confluence/6.6.0/com/atlassian/confluence/core/DateFormatter.html
if you use something like
#set($date = $content.getCreationDate())
<p>date: $action.dateFormatter.formatGivenString("yyyy-MM", $date)</p>
it works.
BTW, if you need to create a custom date object in your macro, my suggestion is to develop a macro through an app in whic you can use your java code (https://developer.atlassian.com/server/confluence/writing-confluence-plugins/ )
Hope this clarify,
Fabio
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.