How to get current date in PST time zone by using server script in scoped app?

Susmitha14
Tera Contributor

How to get current date in PST time zone by using server script in scoped app?

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

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();

find_real_file.png

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

5 REPLIES 5

Tushar Walveka2
Tera Guru

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);