user46567: I'm using the following routine to print the current time on the com port. I would like to capture this as a string so I can display it using ePaper.
void printLocalTime()
{
  time_t rawtime;
  struct tm timeinfo;
  if(!getLocalTime(&timeinfo))
  {
    Serial.println("Failed to obtain time");
   return;
  }
 Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S");
}

produces - Saturday, May 12 2018 12:18:27

user30175: To achieve what you want you probably want to use the "string format time" function strftime (docs). You would write the result in a character buffer, which you can also print directly without having to convert it to String object.
So, the following code should work:
void printLocalTime()
{
  time_t rawtime;
  struct tm timeinfo;
  if(!getLocalTime(&timeinfo))
  {
    Serial.println("Failed to obtain time");
   return;
  }
  char timeStringBuff[50]; //50 chars should be enough
  strftime(timeStringBuff, sizeof(timeStringBuff), "%A, %B %d %Y %H:%M:%S", &timeinfo);
  //print like "const char*"
  Serial.println(timeStringBuff);

  //Optional: Construct String object 
  String asString(timeStringBuff);
}

The overload for Serial.print also does this exact same thing:
size_t Print::print(struct tm * timeinfo, const char * format)
{
    const char * f = format;
    if(!f){
        f = "%c";
    }
    char buf[64];
    size_t written = strftime(buf, 64, f, timeinfo);
    print(buf);
    return written;
}


46567: <p>I'm using the following routine to print the current time on the com port. I would like to capture this as a string so I can display it using ePaper.</p>

<pre><code>void printLocalTime()
{
  time_t rawtime;
  struct tm timeinfo;
  if(!getLocalTime(&amp;timeinfo))
  {
    Serial.println("Failed to obtain time");
   return;
  }
 Serial.println(&amp;timeinfo, "%A, %B %d %Y %H:%M:%S");
}
</code></pre>

<p>produces - Saturday, May 12 2018 12:18:27</p>
 30175: <p>To achieve what you want you probably want to use the "string format time" function <code>strftime</code> (<a href="http://www.cplusplus.com/reference/ctime/strftime/" rel="nofollow noreferrer">docs</a>). You would write the result in a character buffer, which you can also print directly without having to convert it to <code>String</code> object.</p>

<p>So, the following code should work:</p>

<pre class="lang-cpp prettyprint-override"><code>void printLocalTime()
{
  time_t rawtime;
  struct tm timeinfo;
  if(!getLocalTime(&amp;timeinfo))
  {
    Serial.println("Failed to obtain time");
   return;
  }
  char timeStringBuff[50]; //50 chars should be enough
  strftime(timeStringBuff, sizeof(timeStringBuff), "%A, %B %d %Y %H:%M:%S", &amp;timeinfo);
  //print like "const char*"
  Serial.println(timeStringBuff);

  //Optional: Construct String object 
  String asString(timeStringBuff);
}
</code></pre>

<p>The overload for <code>Serial.print</code> also does <a href="https://github.com/espressif/arduino-esp32/blob/master/cores/esp32/Print.cpp#L149" rel="nofollow noreferrer">this exact same thing</a>:</p>

<pre class="lang-cpp prettyprint-override"><code>size_t Print::print(struct tm * timeinfo, const char * format)
{
    const char * f = format;
    if(!f){
        f = "%c";
    }
    char buf[64];
    size_t written = strftime(buf, 64, f, timeinfo);
    print(buf);
    return written;
}
</code></pre>
