Created
March 26, 2014 12:45
-
-
Save cypres/9782309 to your computer and use it in GitHub Desktop.
smpp time parse
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <iomanip> | |
#include <ctime> | |
#include <cstdint> | |
uint64_t unixtime(const char* ts) { | |
std::tm tm; | |
tm.tm_year = (ts[0] - '0') * 10 + (ts[1] - '0'); | |
if (tm.tm_year < 70) tm.tm_year += 2000; | |
tm.tm_mon = (ts[2] - '0') * 10 + (ts[3] - '0'); | |
tm.tm_mday = (ts[4] - '0') * 10 + (ts[5] - '0'); | |
tm.tm_hour = (ts[6] - '0') * 10 + (ts[7] - '0'); | |
tm.tm_min = (ts[8] - '0') * 10 + (ts[9] - '0'); | |
auto tt = std::mktime(&tm); | |
return static_cast<uint64_t>(tt); | |
} | |
int main() { | |
auto ts = ::unixtime("8009041337"); | |
std::cout << "TS: " << std::setfill('0') << std::setw(8) << ts; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment