How to chnage Date format from 2024-08-10 15:18:05 to 2024-Aug-10 03:18:01P M

Dasari Srihari
Tera Contributor

Hi All,

 

How to change date format from 2024-08-14 14:12:01 to 2024-Aug-14 02:12:01 PM, 

 

In incident i want to show as a filed message.

 

 

 

 

 

 

 getCallersLocalTime: function() {
        var id = this.getParameter('sysparm_caller');

        var callerObject = new GlideRecord('sys_user');
        if (callerObject.get(id)) {
            
            
            var time = new GlideDateTime();
            var tz = Packages.java.util.TimeZone.getTimeZone(callerObject.getValue('time_zone'));
            time.setTZ(tz);
            
            var timeZoneOffSet = time.getTZOffset();
   
            time.setNumericValue(time.getNumericValue() + timeZoneOffSet);

            gs.info("Local time is : " + time); // prints Local Date time as : 2022-05-25 11:47:34 

            return time.toString();
        }

    },

 

 

 

 

 

 

2 REPLIES 2

ShubhamGarg
Kilo Sage

Hello @Dasari Srihari ,

 

According yo OOTB article

GlideDateTime - GlideDateTime(GlideDateTime gdt)

Instantiates a new GlideDateTime object set to the time of a specified GlideDateTime object.

The system attempts to match the argument passed to the gdt parameter with the specified internal system format. If the argument does not match the system format, the system attempts to match it to one of the following formats in this order
  • yyyy-MM-dd'T'HH:mm:ss.SSSZ
  • MM/dd/yyyy HH:mm:ss
  • MM-dd-yyyy HH:mm:ss
  • MM-dd-yyyy HH:mm
  • MM-dd-yyyy
  • MM/dd/yy HH:mm:ss
  • MM/dd/yyyy
  • dd-MM-yyyy HH:mm:ss
  • dd-MM-yyyy HH.mm.ss
  • dd-MM-yyyy HH.mm
  • dd-MM-yy HH:mm:ss
  • dd-MM-yy HH.mm.ss
  • dd/MM/yyyy
  • dd-MM-yyyy
  • yyyy-MM-dd HH:mm
  • yyyy-MM-dd
  • dd.MM.yyyy HH:mm:ss
  • dd.MM.yyyy HH.mm.ss
  • dd.MM.yyyy hh:mm:ss a
  • dd.MM.yyyy hh.mm.ss a
  • dd.MM.yyyy
If one of these formats results in a valid date/time, GlideDateTime.isValid() returns true.
Hope it helps.
Regards,
Shubham

ersureshbe
Giga Sage
Giga Sage

Hi,

 

It is my expectation that there will be no necessity to draft scripts. By accessing the 'sys_user' table, you have the ability to modify the 'Date Format' field for an individual user or on a global scale, depending on your business needs.

 

 

Regards,
Suresh.