Ariel Baron
Ariel Baron

Reputation: 351

Is there an alternative to the std::tm structure?

I would like to use std::mktime on a std:: tm like structure. I want to do this because my seconds have double precision and std:: tm only has integer precision for the number of seconds. Is there an alternative structure, that has double precision, that would allow me to use mktime on it?

Upvotes: 1

Views: 782

Answers (1)

Howard Hinnant
Howard Hinnant

Reputation: 219255

I note that one of your tags is [c]. Can't help you there. But if you're in C++11/14, this free open-source library provides all of the functionality of tm and mtkime with arbitrarily fine precision (nanoseconds no problem). It builds on the C++11 std::chrono facilities and adds parsing, formatting, conversions to/from calendar types, and timezone functionality that far exceed the old C API.

There is full documentation. There are video tutorials. There is a gitter chat room. There are github issues. And it is portable across the later versions of Visual Studio, gcc and clang.

Lots of example code here.

Upvotes: 4

Related Questions