- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2015 03:11 PM
ServiceNow seems to store all 'time' columns as the 1970-01-01 + time. So when I run this
var gdt = new GlideDateTime();
gdt.getLocalTime()
I get 1970-01-01 14:59:57
What are the best practices for removing the 1970-01-01? I just want 14:59:57 (actually, I just want the hour and minute in separate variables, but that's a different question).
I can do a string replace to nuke 1970-01-01 but that feels like a kludge. I can't figure out how you can specify the date format to GlideDateTime. setValueUTC(gdt, "HH:mm") does not seem to work... it returns blank.
So how would you do this?
Thanks!
-Robby
Solved! Go to Solution.
- Labels:
-
User Interface (UI)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2015 03:33 PM
I was able to solve the issue - getNumericValue() is the key. It gets us milliseconds since unix epoc (which is 1970-1-1 00:00:00).
So we can convert that to hours/minutes with some simple math.
var gdt = new GlideDateTime();
var gdtTime = new GlideDateTime(gdt.getLocalTime());
var imsTime = gdtTime.getNumericValue();
var imsInHour = 3600000;
var imsInMinute = 60000;
var iLocalHours = Math.floor(imsTime / imsInHour).toFixed(0);
var iLocalMinutes = Math.floor((imsTime - (iLocalHours * imsInHour)) / imsInMinute).toFixed(0);
I don't think max int will be an issue since the number of milliseconds in 24 hours = 86,400,000.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2015 03:33 PM
I was able to solve the issue - getNumericValue() is the key. It gets us milliseconds since unix epoc (which is 1970-1-1 00:00:00).
So we can convert that to hours/minutes with some simple math.
var gdt = new GlideDateTime();
var gdtTime = new GlideDateTime(gdt.getLocalTime());
var imsTime = gdtTime.getNumericValue();
var imsInHour = 3600000;
var imsInMinute = 60000;
var iLocalHours = Math.floor(imsTime / imsInHour).toFixed(0);
var iLocalMinutes = Math.floor((imsTime - (iLocalHours * imsInHour)) / imsInMinute).toFixed(0);
I don't think max int will be an issue since the number of milliseconds in 24 hours = 86,400,000.