# \[Solved\] Convert Timestamp to hours:minutes

**URL:** <https://forums.losant.com/t/solved-convert-timestamp-to-hours-minutes/463>\
**Category:** Help\
**Created:** [April 7, 2017, 9:44am UTC](https://forums.losant.com/t/solved-convert-timestamp-to-hours-minutes/463 "2017-04-07T09:44:27Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![ADB2](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@ADB2](https://forums.losant.com/u/ADB2)\
**Post date:** [October 1, 2019, 7:33pm UTC](https://forums.losant.com/t/solved-convert-timestamp-to-hours-minutes/463/8 "2019-10-01T19:33:30Z")

</div>

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:

> **[My attempt at detecting EST/EDT change automatically](https://community.particle.io/t/my-attempt-at-detecting-est-edt-change-automatically/40272/4)**
>
> @bko, nice code…very clean. Slightly optimized code…version 2 below: // // Last update: 03/11/18 // typedef struct DSTStruct { int year; int startDay; // DST start day in Mar int endDay; ...

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.

---

_[View the full topic](https://forums.losant.com/t/solved-convert-timestamp-to-hours-minutes/463)._
