Danny
Danny

Reputation: 13

How to convert Int to Date format on Grails?

How can I convert an integer (40000) into date format?. In excel can be done by changing the format of the cell from number to date. In that case 40000 = 06/07/2009, the integer is the number of days since 1/1/1900

Is there a function that does this on Grails?

Thank you in advance!!

Upvotes: 1

Views: 1060

Answers (1)

dmahapatro
dmahapatro

Reputation: 50265

Date addDaysToDate(int noOfDays, Date initDate = null) {
    // If init date provided, add date to it otherwise 
    // consider epoch (1/1/1970 GMT) as init date
    ( ( initDate ?: new Date(0) ) + noOfDays ).clearTime()
}

println addDaysToDate( 40000, Date.parse("MM/dd/yyyy", "1/1/1900") )
println addDaysToDate( 40000 )

Upvotes: 3

Related Questions