How to convert date time like this "20030228032647.0Z " into MM-dd-yyyy hh:mm:ss ?

AbdulRahman89
Giga Contributor

How to convert date time like this "20030228032647.0Z " into MM-dd-yyyy hh:mm:ss ?

This date time is being fed through Active Directory integration with ServiceNow and I'd like to process this date time in the Transform Map itself.

Any help would be appreciated!

Thanks in Advance.

1 ACCEPTED SOLUTION

Ahmmed Ali
Mega Sage

Hello,

 

try below code:

var s = "20030228032647";
var v = s.substring(0, 4) + '-' + s.substring(4, 6) + '-' + s.substring(6, 😎 + " " + s.substring(8,10) + ":" + s.substring(10,12) + ":" + s.substring(12,14);
gs.print(v)

 

it worked for me. Output: 

*** Script: 2003-02-28 03:26:47

source: https://stackoverflow.com/questions/10631483/specific-date-format-from-date-string-in-java

Please mark correct/helpful if applicable.

Thanks,
Ali
If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

View solution in original post

2 REPLIES 2

Ahmmed Ali
Mega Sage

Hello,

 

try below code:

var s = "20030228032647";
var v = s.substring(0, 4) + '-' + s.substring(4, 6) + '-' + s.substring(6, 😎 + " " + s.substring(8,10) + ":" + s.substring(10,12) + ":" + s.substring(12,14);
gs.print(v)

 

it worked for me. Output: 

*** Script: 2003-02-28 03:26:47

source: https://stackoverflow.com/questions/10631483/specific-date-format-from-date-string-in-java

Please mark correct/helpful if applicable.

Thanks,
Ali
If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

Simon Christens
Kilo Sage

Or you can use:

var d = '20030228032647.0Z';

var gdt = new GlideDateTime();
gdt.setValueUTC(d, 'yyyyMMddHHmmss');

gs.print(gdt.getValue() + ' - ' + gdt.getDisplayValue());

Value is server formated value and displayValue is locally formated incl local timezone