Unix / Epoch time
Unix time (also known as POSIX time or Epoch time) is a system for describing instants in time, defined as the number of seconds that have elapsed since 00:00:00 Coordinated Universal Time (UTC), Thursday, 1 January 1970, not counting leap seconds. It is used widely in Unix-like and many other operating systems and file formats.
Example: 1419086327 (2014-12-20T14:38:47Z)
Waspmote API defines some functions to use this time format which can be useful in order to translate dates into seconds and perform addition or subtraction of time.
An example of the functions that are shown below: https://development.libelium.com​/​rtc-08-unixepoch-time/

Getting Epoch time

The function getEpochTime() permits to calculate the Unix time associated to a specific year, month, day, hour, minute and second values. It is possible to indicate these values as input or use the current values of the RTC.
Example of use:
1
{
2
// Define variable to store Epoch time
3
unsigned long epoch;
4
// Example: Get Epoch time from RTC values
5
epoch = RTC.getEpochTime();
6
// Example: Get Epoch time from input values(i.e: 2014-12-20 at 14:38:47)
7
epoch = RTC.getEpochTime( 14, 12, 20, 14, 38, 47 );
8
}
Copied!
The function getEpochTime() updates the RTC attributes because it calls getTime() function.

Breaking Epoch time into 'Time and Date'

The function breakTimeAbsolute() permits to convert the input epoch time to time and date values (as UTC components). Thus, it can be useful to add/subtract times. For example: get Epoch time from RTC and add several seconds to calculate a new time instant.
The structure called timestamp_t is defined in WaspRTC class for converting epoch time into UTC timestamps.
Example of use:
1
{
2
// Define variable for UTC timestamps
3
timestamp_t time;
4
// Break Epoch time into UTC time
5
RTC.breakTimeAbsolute( epoch, &time );
6
7
// Available info: UTC Date
8
USB.print( time.year, DEC );
9
USB.print( time.month, DEC );
10
USB.print( time.date, DEC );
11
USB.print( time.hour, DEC );
12
USB.print( time.minute, DEC );
13
USB.print( time.second, DEC );
14
}
Copied!
The function breakTimeOffset() permits to convert the input (great period of seconds) into offset time values (as the number of days, hours, minutes and seconds that the input argument defines). Thus, it can be useful to add/subtract times. For example: get Epoch time from RTC in different instants and then calculate the difference as number of days, hours, minutes and seconds.
The structure called timestamp_t is defined in WaspRTC class for converting great periods of seconds into number of days, hours, minutes and seconds.
Example of use:
1
{
2
// Define variable for timestamps
3
timestamp_t time;
4
// Get offset time from ‘411361’ seconds
5
RTC.breakTimeOffset( 411361, &time );
6
7
// Available info: ‘4’ days, ‘18’ hours, ‘16’ minutes and ‘1’seconds
8
USB.print( time.date, DEC );
9
USB.print( time.hour, DEC );
10
USB.print( time.minute, DEC );
11
USB.print( time.second, DEC );
12
}
Copied!