[Solved] Convert Timestamp to hours:minutes

If you know the timezone, a method of determining daylight savings time without using Google APIs is to simply compare the current month and day to the DST dates. I have a Timer trigger run the following code in a Function node once a day and update a storage variable for use elsewhere in the workflow.

var UTCoffset = -5; // Eastern US standard time, adjust for your location
var now = new Date();
var month = now.getMonth() + 1; // Adjusted to match C
var weekday = now.getDay() + 1; // Adjusted to match C
var day = now.getDate(); 
var previousSunday = day - weekday + 1;

if (month < 3 || month > 11) {
	var UTCoffset = UTCoffset; 
}
else if (month > 3 && month < 11) {
	var UTCoffset = UTCoffset + 1; 
}
else if (month == 3) {
	var UTCoffset = (previousSunday >= 8)? UTCoffset + 1 : UTCoffset;
}
else {
	var UTCoffset = (previousSunday <= 0)? UTCoffset + 1 : UTCoffset;
}
payload.data.UTCoffset = UTCoffset;

This algorithm was based on a function (in C) posted by Ric DelMar to a Particle forum:

I use a Date/Time node to add this offset to a workflow timestamp in UTC to create one that’s in local time. A second Date/Time node can be used to format the timestamp into HH:mm or whatever is needed to pass into SMS, email, etc.

2 Likes