Skip to content

Instantly share code, notes, and snippets.

@usagi
Last active December 10, 2020 03:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save usagi/22937ea50a61c4c06aa6 to your computer and use it in GitHub Desktop.
Save usagi/22937ea50a61c4c06aa6 to your computer and use it in GitHub Desktop.
std::chrono::steady_clock to ISO8601
auto to_string_iso8601( const std::chrono::steady_clock::time_point& t )
-> std::string
{
using namespace std::chrono;
const time_t ct
( ( duration_cast< seconds >( system_clock::now( ).time_since_epoch( ) )
+ duration_cast< seconds >( t - steady_clock::now( ) )
).count( )
);
std::string r = "0000-00-00T00:00:00Z.";
std::strftime( const_cast< char* >( r.data( ) ), r.size( ), "%FT%TZ", std::gmtime( &ct ) );
return r;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment