Custom Scripted field - Closed Date Scripted field error with Date vs Timestamp

I have a custom field called “Closed” that is a Scripted Field using a Date Time Range picker template. This is the Date and Time the Issue was closed. It is derived by the last occurrence of when an issue transitions to closed status.

The script that is failing is using a depreciated functions and in trying to correct this I receive that a Date is expected and I’m assigning a Timestamp.

The Original script is:

import com.atlassian.jira.ComponentManager
def componentManager = ComponentManager.getInstance()
def changeHistoryManager = componentManager.getChangeHistoryManager()
def lastClosed=null
changeHistoryManager.getChangeItemsForField(issue, “status”).each {
if(it.toString == “Closed”)
{
if(it.getCreated()>lastClosed)
lastClosed = it.getCreated()
}
}
return lastClosed

The Script that I have been working on is below, it works in the Script Console but not in the Preview when try it:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.changehistory.ChangeHistoryManager
import com.atlassian.core.util.DateUtils
import java.util.Date
//import java.sql.Timestamp

MutableIssue issue = ComponentAccessor.getIssueManager().getIssueObject(“ATJIRA-19”);
ChangeHistoryManager changeHistoryManager = ComponentAccessor.getChangeHistoryManager();

def lastClosed=null
def X = changeHistoryManager.getChangeItemsForField (issue, “status”)
for (item in X?.reverse())
{
if(item.getToString() == ‘Closed’)
{
if(item.getCreated())
{
//Date mylastClosed = new Date(item.created);
lastClosed = item.getCreated();
//lastClosed=new Date(item.getCreated());
log.error(“X = ${item.getToString()} … ${item.getCreated()} lastClosed ${lastClosed}”);
}
break;
}
}

return lastClosed