SparkTime.hourString(value) returning wrong value

I have created a timer that is triggered by a button being unpressed, The timer track elapsed time and update the timer on an 16x2 lcd.

Everything works OK, but the hourString returns “01” when the timer starts, and it should be “00”

What am I doing wrong?

The statment that is failing is in line 60.
Here is my code:

// This #include statement was automatically added by the Particle IDE.
// This is a program to trac time elapsed since a button is unnpresed, and display the time and elapsed time on a 16x2 lcd display (1602a)
#include "SparkTime/SparkTime.h"	
#include "application.h"
//#include "SparkTime/SparkTime.h"
#include "LiquidCrystal.h"
//#include "LiquidCrystal/LiquidCrystal.h"

LiquidCrystal lcd(D0, D1, D2, D3, D4, D5);

UDP UDPClient;
SparkTime rtc;

unsigned long currentTime;
unsigned long lastTime = 0UL;
String timeStr;
unsigned long start;
unsigned long timeUsed;

void setup() {
rtc.begin(&UDPClient, "");
rtc.setTimeZone(+1); // gmt offset
// set up the LCD's number of columns and rows: 
start =;

void loop() {

// set the cursor to column 4, line 0 and print time
lcd.setCursor(4, 0);
currentTime =;
if (currentTime != lastTime) {
timeStr = "";
timeStr += rtc.hourString(currentTime);
timeStr += ":";
timeStr += rtc.minuteString(currentTime);
timeStr += ":";
timeStr += rtc.secondString(currentTime);	

// check sensor to detect change, this trigers the timer
if (analogRead(0) < 3500) {
  start =;
// used for debuging 
// lcd.setCursor(10, 1);
// lcd.print(analogRead(0));

// Print timeUsed since trigger started
  timeUsed = (;
  timeStr = "";
  timeStr += rtc.hourString(timeUsed);  // ********* Why does this line display "01" when initiatd from 0?
  timeStr += ":";
  timeStr += rtc.minuteString(timeUsed); // ******** this is corretly showing "00" from initiation.
  timeStr += ":";
  timeStr += rtc.secondString(timeUsed); // ******** this is corretly showing "00" from initiation.

  lastTime = currentTime;


I believe that the code is applying your Time Zone offset of +1 to time. The library is not really set up to print time differences as you are doing.

You can probably set your time zone offset to zero and set it back to +1 after you get the values you want.


Thank you! This did it.

1 Like