pneave icon

Get the time in ISO 8601 format

pneave | PRO | 10/02/19 01:21:51 PM UTC | 0 ⭐ | 339 👁️ | Never ⏰ | []
C++ |

410 B

|

None

|

0 👍

/

0 👎

// Return the current local time in ISO 8601 format which includes
// the offset from UTC.
//         i.e. 2019-09-27T13:51:30+01:00
std::string timeISO()
{
   auto now = std::chrono::system_clock::now();
   auto in_time_t = std::chrono::system_clock::to_time_t(now);
 
   std::tm tm = *std::localtime(&in_time_t);
 
   std::stringstream ss;
   ss << std::put_time(&tm, "%FT%T%z");
   return ss.str();
}

Comments