How to effectively analyze the date (increase)

I have a char *date string that I want to parse. In this case, a very simple format: 2010-10-28T16:23:31.428226(common ISO format).

I know with Boost, I can make it out, but at a terrible price. I have to create a stream of rows, possibly a row, and then copy the data back and forth. Is there any way to parse char *without allocating extra memory. Stack objects are accurate, so reuse a heap object.

Any easy way would be great too!;)

Edit: I need a result in microseconds from the era.

+3
source share
2 answers

C . strptime (...):

struct tm parts = {0};
strptime("2010-10-28T16:23:31", "%Y-%m-%dT%H:%M:%S", &parts);

, . , sscanf (...) :

unsigned int year, month, day, hour, min;
double sec;
int got = sscanf(
     "2010-10-28T16:23:31.428226", 
     "%u-%u-%uT%u:%u:%lf",
     &year, &month, &day, &hour, &min, &sec
);
assert(got == 6);
+2

, ?

, , - , :

const char* date = "2010-10-28T16:23:31.428226";
int year = (((date[0] ^ 0x30)) * 1000) + ((date[1] ^ 0x30) * 100) + ((date[2] ^ 0x30) * 10) + (date[3] ^ 0x30);
int month = ((date[5] ^ 0x30) * 10) + (date[6] ^ 0x30);
int day = ((date[8] ^ 0x30) * 10) + (date[9] ^ 0x30);

.

, , ... , ...

, , , , , ?

0

Source: https://habr.com/ru/post/1772061/


All Articles