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

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

Ankur Bawiskar
Tera Patron
Tera Patron

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

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

@Susmitha 

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

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

Taha6
Tera Expert

There is an OOB script include for that rmConvertTimeZone 

find_real_file.png