The below-given sample code can be used to convert the user’s preferred date format onto a specific date format using the ‘moment.js” library.
Script Sample:
var userObj = runtime.getCurrentUser();
var DateFormat = userObj.getPreference({ name: ‘DATEFORMAT’ });
if (DateFormat) {
DateFormat = DateFormat.split("Mon").join("MMM");
DateFormat = DateFormat.split("MONTH").join("MMMM");
}
function formatDate(dateString, format) {
var formattedDate =moment(dateString,format,true).format('DD/MM/YYYY');
return formattedDate;
}
var inputDate = date;
date = formatDate(inputDate, DateFormat);