Tom23
Tera Expert

It's very possible I'm fixing something with a better solution, but I came across this when trying to to add time to a Date/Time field. Running addSeconds() resulted in a time 1 hour earlier than the current time. So, say we did a new GlideDateTime() and got a result of 11/06/2019 14:45, then added 300 seconds, then logged the output of said command, we would end up with 11/06/2019 13:50. I believe this is down to the platform not using British Summer Time - something that, being in the UK would affect us as we'd end up with time-travel on our records - not ideal.

The solution, I thought, was getLocalTime() but when I then did the addSeconds calculation, the time was right, but the date was returning as 01/01/1970! I've ended up with the below script which - does the calculation in local time, grabs just the time from the resulting date and time, grabs the local date, then concatenates those into a variable I can then use to insert where needed. 

var sgdt = new GlideDateTime();
	sgt = sgdt.getLocalTime();
	sgt.addSeconds(300);
var sTime = sgt.getByFormat('HH:mm:ss');//24 hour format, use ('hh:mm:ss') for 12 hour
var sgd = sgdt.getLocalDate();
var sTimeDate = sgd + ' ' + sTime;

 

 

Version history
Last update:
‎06-11-2019 06:58 AM
Updated by: