Getting UTC with TZ from a Yun


How to get the local time in UTC format with adjusted time included without going through the acrobatic of the following code?

In Linux, date ”+%s z%” returns seconds since 1970-01-01 00:00:00 UTC + the time zone diff. as 1234567890 +0200, in my case. But I’d like Linux to return the hours zone added to the UTC time.


time_t epoch() {
  String result;
  Process time;
  //time.addParameter("+%Y/%m/%d %H:%M:%S");
  //%s = seconds since 1970-01-01 00:00:00 UTC
  //%z = +hhmm numeric time zone (e.g., -0400)
  time.addParameter("+%s %z"); //add this to date;

  while (time.available() > 0) {
    char c =;
    if (c != '\n')
      result += c;
  String epoch = result.substring(0, result.indexOf(" "));  //get UTC
  int first = result.indexOf(" ") + 3;
  int sec = first + 1;
  String tz = result.substring(first, sec); //get time zone
  return epoch.toInt() +  (tz.toInt() * 3600); //convert to local time by adding time zone

Does that mean you want the seconds since beginning of 1970 in your timezone? That does not make sense, since this is a not unique value (summer/winter time change).

You can calculate that strange value if you really like it. Just split the string at the plus/minus sign and add/subtract the later value multiplied by 3600.