how to display getDateTime() DDMMYYHHMMSS

service buzz
Tera Contributor

Can anyone help me displaying the getDateTime() value DDMMYYHHMMSS format

 

Thanks,

 

1 ACCEPTED SOLUTION

Anil Shewale
Mega Guru

Hi

To change the format, you first need to set up GlideDateTime using your current format 

var date = '10 Jul 2018 12:30:00';
var simpleDateFormat = 'dd MMMM yyyy HH:mm:ss'; // Simple Date Time format
var gdt = new GlideDateTime();

gdt.setDisplayValue(date,simpleDateFormat); //Set time using current TZ
gs.addInfoMessage(gdt.getDisplayValue()); // Output time in current TZ
2018-07-10 12:30:00 PM

Once your GlideDateTime object has the correct time, you can manipulate it as you need.

gdt.addDays(7);
gs.addInfoMessage(gdt.getDisplayValue());
2018-07-17 12:30:00 PM

And back again to your original format, with the added 7 days

var gd = gdt.getLocalDate();
var gt = gdt.getLocalTime();

gs.addInfoMessage(gd.getByFormat('dd MMM yyyy') + gt.getByFormat(' HH:mm:ss'));

 

17 Jul 2018 12:30:00

refer this artical for more:

https://community.servicenow.com/community?id=community_blog&sys_id=bc0e6a2ddbd0dbc01dcaf3231f961931

If it help mark helpful or correct 

Thanks and regards

Anil

 

View solution in original post

5 REPLIES 5

The SN Nerd
Giga Sage
Giga Sage

Please bookmark / mark my blog The Secrets of GlideDateTime as helpful if it contributed to your resolution 🙂


ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022