Date Format in Script Output

Mike McCall
Giga Guru

Is there an easy way to script date fields into whatever format(s) I want?

/* The Created field prints as "2015-10-27 19:52:33" (but I want the time to show 7:52 PM). */

gs.print(current.sys_created_on);

/* Running the field through GlideDateTime gets me to the same output... */

var glideDateTime = new GlideDateTime(current.sys_created_on);

gs.print(glideDateTime.getValue()); // This also returns "2015-10-27 19:52:33"

/* ...so, NOW WHAT? */

In the past, I've done painful translations on my own to create a string by pulling out individual elements and putting them back in the order I want. I know I could reuse this work through something like a Script Include...but has all that already been done for me?

5 REPLIES 5