- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2021 10:49 PM
How to get current date in PST time zone by using server script in scoped app?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2021 10:57 PM
Hi,
You cannot convert time in Scoped application
You will have to create script include in Global Scope and make it Accessible from All Scopes
Then call it from your Scoped application
var ConvertTimeZone = Class.create();
ConvertTimeZone.prototype = {
initialize: function() {
},
convertTime: function(){
var time = new GlideDateTime();
gs.info('GMT time is->'+time);
var tz = Packages.java.util.TimeZone.getTimeZone('PST');
time.setTZ(tz);
var timeZoneOffSet = time.getTZOffset();
time.setNumericValue(time.getNumericValue() + timeZoneOffSet);
gs.info('PST time is->'+time);
return time;
},
type: 'ConvertTimeZone'
};
Call it like this
var pstTime = new global.ConvertTimeZone().converTime();
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2021 10:57 PM
Hi,
You cannot convert time in Scoped application
You will have to create script include in Global Scope and make it Accessible from All Scopes
Then call it from your Scoped application
var ConvertTimeZone = Class.create();
ConvertTimeZone.prototype = {
initialize: function() {
},
convertTime: function(){
var time = new GlideDateTime();
gs.info('GMT time is->'+time);
var tz = Packages.java.util.TimeZone.getTimeZone('PST');
time.setTZ(tz);
var timeZoneOffSet = time.getTZOffset();
time.setNumericValue(time.getNumericValue() + timeZoneOffSet);
gs.info('PST time is->'+time);
return time;
},
type: 'ConvertTimeZone'
};
Call it like this
var pstTime = new global.ConvertTimeZone().converTime();
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2021 10:58 PM
Hi,
this link has mentioned for scoped application but I haven't tried it
Scoped application - How to get current date/time of a specific timezone.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2021 02:34 AM
Hope you are doing good.
Did my reply answer your question?
If so, please mark appropriate response as correct & helpful so that the question will appear as resolved for others who may have a similar question in the future.
Thanks!
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-26-2021 08:07 AM