Equivalent Glide class for "Packages.java.util.TimeZone.getTimeZone"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2017 12:08 PM
Everyone,
I have seem the script to convert a certain date/time to a prefered timezone using "Packages.java.util.TimeZone.getTimeZone". It works well in the 'global' scope but not in customized applications.
Questions:
Is there an equivalent Glide class for "Packages.java.util.TimeZone.getTimeZone"?
a) IF yes, please share with me and I'll explore more.
b) IF no, what is a working alternative solution?
Here's my script:
//STEP 1: set extracted time in seconds to GlideDateTime | |
var gdt = new GlideDateTime("1970-01-01 00:00:00"); | |
gdt.addSeconds(timeInSeconds); |
//STEP 2: set timezome | |
var tzInstance = gs.getProperty("glide.sys.default.tz"); //get system timezone | |
var time = new GlideDateTime(gdt.getValue()); //set datetime value |
var tz = Packages.java.util.TimeZone.getTimeZone(tzInstance); //initialize tareget timezone
time.setTZ(tz); //invoke timezone to target time
var timeZoneOffSet = time.getTZOffset(); // get offset of timezone set above
time.setNumericValue(time.getNumericValue() + timeZoneOffSet); // add offset to current time
return time; |
I appreciate any leads...
Thanks,
Dor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2017 12:37 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2017 02:59 PM
What is it you're actually after here... displaying a date/time from a database record according to a user's locale preferences?
Note that gs.now() will show them the timezone-sensitive current date/time.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2017 08:03 AM
I am actually importing data from BMC Remedy to ServiceNow. The extracted dates are in seconds. STEP 1 converts that to GlideDateTime but it in GMT. So, STEP 2 is to convert it to the local timezone, which I found in another thread. This works properly when I am in the 'global' scope. Unfortunately, I have to deal with a customized scope application for this task and it would work there. The import error points to this line of script. Im looking for any tips or leads.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2017 08:56 AM
Not ideal, but the way I have sometimes had to get around access to API's from scoped applications is to create a Global Script include that is available to all scopes and create a function in there that makes the API call. Again its not the best practice but it does work.