FreeMarker - add days to dates

Viewed 482

I am trying to add 1 day to the current date. I do know ${.now?date} = The Current Date. But how do I add a day to that? I read that you have to use milliseconds (86,400,000 milliseconds) but I'm unsure what the operation should be.

2 Answers

The detailed answer is here:

<#assign currentDate = .now>
Current Date : ${currentDate?date}<br>
<#assign numberOfDays = 1?long>
<#assign timeInMillisecond = (1000 * 60 * 60 * 24 * numberOfDays) >
<#assign aDate = currentDate?long + timeInMillisecond?long>
<#assign Diff = aDate?long>
<#assign OneDayAfterDate = Diff?number_to_date>
<br>Date after ${numberOfDays} Days : ${OneDayAfterDate}<br>
<br>Date after ${numberOfDays} Days in UTC format : ${OneDayAfterDate?iso_utc}<br>

Figured it out!

${(.now?long + 86400000)?number_to_date }
Related