I\'m working with the Azure REST API and they are using this to create the request body for table storage:
DateTime.UtcNow.ToString(\"o\")
You can use this function which uses std::put_time with a std::ostringstream to generate the resulting std::string.
#include
#include
#include
#include
/**
* Generate a UTC ISO8601-formatted timestamp
* and return as std::string
*/
std::string currentISO8601TimeUTC() {
auto now = std::chrono::system_clock::now();
auto itt = std::chrono::system_clock::to_time_t(now);
std::ostringstream ss;
ss << std::put_time(gmtime(&itt), "%FT%TZ");
return ss.str();
}
// Usage example
int main() {
std::cout << currentISO8601TimeUTC() << std::endl;
}
Reference: https://techoverflow.net/2018/03/30/iso8601-utc-time-as-stdstring-using-c11-chrono/