Skip to content

TimeSpanClass

Arnd edited this page Dec 12, 2020 · 2 revisions

The TimeSpan class (as well as the related DateTime class) have been taken from Adafruit's RTClib which in turn was forked from Jeelab's RTClib. The TimeSpan class encompasses the definitions needed to store and manipulate a specific length of time without having a specific date/time.

Several methods can be used to instantiate this class depending upon what format the span is defined:


TimeSpan span1(seconds);                // Number of seconds
TimeSpan span2(12,18,05,0)              // 12 days, 18 hours, 5 minutes and 0 seconds
TimeSpan span3(span2);                  // Instantiate from another TimeSpan instance

The stored values can be manipulated by:


span1 = span1 + span2;                  // Add another time span
span1 = span1 - span2;                  // Subtract another time span

And finally the following methods exist to retrieve component information from an instance of the class:


Serial.print(span1.days());              // Extract days from DateTime
Serial.print(span1.hours());             // Extract hours from DateTime
Serial.print(span1.minutet());           // Extract minutes from DateTime
Serial.print(span1.seconds());           // Extract seconds from DateTime
Serial.print(span1.totalseconds());      // Extract total number of seconds in span
Clone this wiki locally