Advertisement
pneave

Get the time in ISO 8601 format

Oct 2nd, 2019
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.41 KB | None | 0 0
  1. // Return the current local time in ISO 8601 format which includes
  2. // the offset from UTC.
  3. //         i.e. 2019-09-27T13:51:30+01:00
  4. std::string timeISO()
  5. {
  6.    auto now = std::chrono::system_clock::now();
  7.    auto in_time_t = std::chrono::system_clock::to_time_t(now);
  8.  
  9.    std::tm tm = *std::localtime(&in_time_t);
  10.  
  11.    std::stringstream ss;
  12.    ss << std::put_time(&tm, "%FT%T%z");
  13.    return ss.str();
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement