It's really common to need to send a UTC time string to a server, or log it in a data logger. Here's a version I've been writing with some frequency that might be a good addition to the API, once this function is optimized.
String getUTC() {
//2015-03-25T12:00:00Z
String result = "20";
if (rtc.getYear() < 9) {
result += "0";
}
result += String(rtc.getYear());
result += "-";
if (rtc.getMonth() < 9) {
result += "0";
}
result += String(rtc.getMonth());
result += "-";
if (rtc.getDay() < 9) {
result += "0";
}
result += String(rtc.getDay());
result += "T";
if (rtc.getHours() < 9) {
result += "0";
}
result += String(rtc.getHours());
result += ":";
if (rtc.getMinutes() < 9) {
result += "0";
}
result += String(rtc.getMinutes());
result += ":";
if (rtc.getSeconds() < 9) {
result += "0";
}
result += String(rtc.getSeconds());
result += "-5";
return result;
}
It's really common to need to send a UTC time string to a server, or log it in a data logger. Here's a version I've been writing with some frequency that might be a good addition to the API, once this function is optimized.