There are many links to achieve this but I can't actually find a code example from the accepted answers (that doesn't use boost), what would be the most efficient way to have something such as this:
char date[] = "2021-01-01";
long double seconds = SecondsSince1970(date);
and an output of something like 10000000000 or however many seconds that is?
Edit: (achieved in C++ by)
std::tm t = {};
std::istringstream ss("2010-11-04T23:23:01Z");
if (ss >> std::get_time(&t, "%Y-%m-%dT%H:%M:%S")){
std::cout << std::put_time(&t, "%c") << "\n" << std::mktime(&t) << "\n";
}
I guess an extension to this question is how can I replicate this C++ code but without the use of istringstream
so it doesn't have to allocate memory, rather it just goes directly from the raw char []
array to seconds?