Options
- 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.
1 ACCEPTED SOLUTION
Options
- 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
Regards,
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
5 REPLIES 5

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2022 05:24 AM
You can convert time in Scoped application as well.
Try this:
var strConvertedDateTime = new GlideScheduleDateTime(new GlideDateTime()).convertTimeZone("UTC", "PST");
var gdtConvertedDateTime = new GlideDateTime(strConvertedDateTime)
gs.info("Converted Time: "+gdtConvertedDateTime);