Convert date to system preferred date

We need to use Date Time otherwise the Date will be different based on Time Zone. We will get the system information same date and Time. 

/**

        * @description Covert the date based on the Carton Cloud format.

        * @param {Date} dateValue

        * @returns {Date} newDate

        */

        const convertDateToFormat = (dateValue) => {

            try {

                let dateFormat = runtime.getCurrentUser().getPreference({ name: ‘DATEFORMAT’ });

                let timeZone = runtime.getCurrentUser().getPreference({

                    name: ‘TIMEZONE’

                });

                let today = format.format({

                    value: dateValue,

                    type: format.Type.DATETIME,

                    timezone: timeZone,

                    format: dateFormat

                });

                today = format.parse({

                    value: today,

                    type: format.Type.DATETIME,

                });

                // log.debug(“formatted date”, formattedDate)

                return today;

            }

            catch (e) {

                log.error(“convertDateToFormat”, e);

                return “”;

            }

        }

Leave a comment

Your email address will not be published. Required fields are marked *