The joy of getTime() & getByFormat()

The joy of getTime() & getByFormat()

I looked at the result I got "*** Script: [DEBUG] 06:00:00" and then I looked at the code:

var gdt = new GlideDateTime("2014-08-31 18:00:00");

var gt = gdt.getTime();

gs.debug(gt.getByFormat('hh:mm:ss'));

Why didn't I get 18:00:00 in the result? I couldn't see any parameter to tell the code to go 24H instead of having some wicked way of AM/PM. I couldn't get it off my mind even if I just thought "okay, let's do some more coding to get out the time from the variable instead". So after asking around, there was a very simple way. Just replace hh with HH and I got what I wanted. I couldn't find any documentation about that right there and perhaps everyone else knows about it :P. But if I'm not alone, just have the code like this and you will be fine:

var gdt = new GlideDateTime("2014-08-31 18:00:00");

var gt = gdt.getTime();

gs.debug(gt.getByFormat('HH:mm:ss'));

And if you are too lazy like me, I got the code snippet on the GitHub as well: https://github.com/goranlundqvist/YouTube

Take care, 

//G?ran

When I faced similar issue, I had to convert timezone to fetch the correct time. Happy to know this functionality, simple and easy!! Lot of hidden stuff in there!!

回复
Purbali Paul Choudhury

ServiceNow Certified Technical Architect (CTA) | Senior ServiceNow Architect

5 年

If I do HH:MM:ss it gives 18:01:00 instead of 18:00:00!

回复
Jason Stephens

Principal Consultant at Slalom

5 年

Nice find! I would have been stuck on that one for a while... :)

回复
Vibhor Dwivedi

Principal Consultant at Infosys

5 年

Good finding! Looks like more details on Time format can be found here .. https://docs.servicenow.com/bundle/geneva-servicenow-platform/page/administer/time/reference/r_TimeFormat.html

Kushal Tiwari

Sr. Technical Consultant

5 年

Thanks for the info..I was stuck in similar issue and your post saved lots of my time.

要查看或添加评论,请登录

G?ran Lundqvist - ServiceNow Witch Doctor的更多文章

  • How to create external search source "Search Chuck" in ServiceNow

    How to create external search source "Search Chuck" in ServiceNow

    Earlier this week I took the Service Portal Fundamentals class so I could get my voucher for the Micro-cert. Even if…

    4 条评论
  • How to get the fulfillers attention with connect

    How to get the fulfillers attention with connect

    Had a hard time coming up with a good headline for this article. But at least I got your attention.

    7 条评论
  • Client script be gone! Here comes UI Policy!

    Client script be gone! Here comes UI Policy!

    It almost passed my eyes, but luckily Philip made me aware of it in one of my other posts about not using DOM…

    11 条评论
  • SLA Breakdown

    SLA Breakdown

    There are so much new things in London, both big and small stuff. It seems like there just isn't enough time to show it…

    7 条评论
  • Journey into Virtual Agent - Part 2

    Journey into Virtual Agent - Part 2

    Here comes the followup video that I promised when doing Virtual Agent setup in ServiceNow Part 1. This time we go a…

    6 条评论
  • Show reports in Service Portal? Easy peasy

    Show reports in Service Portal? Easy peasy

    Many people have asked for an easy way to publish reports within the Service Portal. And there answer has actually been…

    25 条评论
  • Activating Virtual Agent in ServiceNow - Part 1

    Activating Virtual Agent in ServiceNow - Part 1

    When I write this we all are sitting waiting for the public release of London. We have been playing around with it in…

    7 条评论
  • Short URL for knowledge articles and the magic of processor

    Short URL for knowledge articles and the magic of processor

    I had a question on the community that was kind of tricky, but still the use case was really good. It's was all about…

    21 条评论
  • Hard work pays off

    Hard work pays off

    Normally I write stuff about ServiceNow; how functionality works or other fun stuff. This time it's on a more personal…

    3 条评论
  • Rollback and delete recovery

    Rollback and delete recovery

    When ServiceNow releases a new version there are always functionality that you don't read about, but suddenly pops up…

    11 条评论

社区洞察

其他会员也浏览了