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

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

 

Thanks for reply.colons in this format ?

will it work If i give like this getByFormat('HHMMSS')

 

getByFormat(' HH:mm:ss'));

Hi,

Try this code in Background script:

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

gs.print(gd.getByFormat('dd MM yy') + gt.getByFormat(' HH:mm:ss'));

output:

find_real_file.png

Please mark as Correct and Helpful, if your issue is resolved

Regards,

Subhojit Das

 

Jaspal Singh
Mega Patron
Mega Patron

Hi,

 

Instead of recommending one option you can go through link that has all possible combinations.