Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function(s) to return ISO8601 time strings #35

Open
tigoe opened this issue Mar 1, 2018 · 0 comments
Open

Add function(s) to return ISO8601 time strings #35

tigoe opened this issue Mar 1, 2018 · 0 comments
Labels
type: enhancement Proposed improvement

Comments

@tigoe
Copy link

tigoe commented Mar 1, 2018

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;
}
@tigoe tigoe added the type: enhancement Proposed improvement label Mar 1, 2018
@tigoe tigoe changed the title Add function(s) to return ISO8602 time strings Add function(s) to return ISO8601 time strings Mar 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement Proposed improvement
Projects
None yet
Development

No branches or pull requests

1 participant