Here we have used to fetch the system preference date format and time zone and using the format module.
let dateFormat = runtime.getCurrentUser().getPreference({
name: ‘DATEFORMAT’
});
let timeZone = runtime.getCurrentUser().getPreference({
name: ‘TIMEZONE’
});
let today = new Date();
today = format.format({
value: today,
type: format.Type.DATE,
timezone: timeZone,
format: dateFormat
});
The above code returns the code as String type.
today = format.parse({
value: today,
type: format.Type.DATE,
});
The parse will return as date object so we can use for date calculations.