Function to convert Date to specified format based on preference

    /**

        * @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’ });

                //log.debug(“dateFormat”,dateFormat)

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

                    name: ‘TIMEZONE’

                });

                //log.debug(“timeZone”,timeZone)

                let today = format.format({

                    value: dateValue,

                    type: format.Type.DATETIME,

                    timezone: timeZone,

                    format: dateFormat

                });

                today = format.parse({

                    value: today,

                    type: format.Type.DATETIME,

                });            

                return today;

            }

            catch (e) {

                log.error(“convertDateToFormat”, e);

                return “”;

            }

        }

Leave a comment

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