Electron Particle.syncTime() not working

Hi, I am having problems with the time sync on the electron. It is currently 4+ hours ahead of where it should be. The battery discharged previously and never had synced properly afterwards. I have added the following code to the firmware with no success:

#define ONE_DAY_MILLIS (24 * 60 * 60 * 1000)
unsigned long lastSync = millis();

void loop() {

if (millis() - lastSync > ONE_DAY_MILLIS) {
        // Request time synchronization from the Particle Cloud
        lastSync = millis();


Any help would be appreciated. Thanks

Is is exactly 4 hours ahead? Did you set the time zone, and account for daylight savings time?

1 Like

Thanks @Ric for the quick response. It appears to be exactly 4 hours ahead. My time zone is Eastern NA, Toronto specifically. How would I check the time zone setting and/or change the setting if it is incorrect? Does particle cloud not account for Daylight savings?

No, currently the Particle time functions don’t take into account daylight savings time. You need to set the timezone yourself.


You can use a function like this to determine if daylight savings time is in effect or not, and adjust your timezone accordingly (for the US anyway. Does Canada follow the same dates?).

bool isDST(int dayOfMonth, int month, int dayOfWeek) { 
    if (month < 3 || month > 11) return false;
    if (month > 3 && month < 11) return true;
    int previousSunday = dayOfMonth - dayOfWeek + 1;
    //In march, we are DST if our previous sunday was on or after the 8th.
    if (month == 3) return previousSunday >= 8;
    //In november we must be before the first sunday to be dst.
    //That means the previous sunday must be before the 1st.
    return previousSunday <= 0;

After Edit: The function isDST() is available now in version 0.6.0, but that’s still prerelease.

For that the device would need to know your desired time zone. IP is not reliable for that (e.g. VPN).
The default time zone for Particle devices (and probably most other IoT devices) is UTC, which has no DST.

Thank you. I placed the Time.zone(-4); in the setup() and the time stamp on the particle.publish() is still incorrect. It seems to be defaulting to UTC (i.e. 4+ hours ahead)?

The time stamp in the Particle.publish is always in UTC. Setting Time.zone will give you the correct time on your device when you are using Time.hour(), Time.day(), etc. If you want the local time on whatever device or computer is subscribing to the published event, then you need to convert it at that end; after all, the receiver could be in a different time zone than the sender, and the receiver should know where it is, but the sender might not.


Thank you for the clarification. Makes perfect sense!