Failed to get fraction of seconds using strptime ()

I am getting the date in YYYY-MM-DDThh: mm: ss [.S +] [Z | + -hh: mm] this format. and i am trying to copy this value with strptime

as below

struct tm time = {0};
char *pEnd = strptime(datetime, "%Y-%m-%dT%H:%M:%S%Z", &time);

      

But I can't copy a fraction of a second as it strptime

doesn't support it in C ++.

So what should I do?

I found a solution using gettimeofday()

. but I am already getting the date and time in 'datetime' so please help me find a satellite for this ... I can use poco as well. but even they take local time.

+3


source to share


2 answers


You can remove the "S" component from the string before parsing with strptime

, and then use it however you like later (it won't be anywhere in the standard struct tm

- there are no subfield fields there). Simple datetime.find('.')

and from there, or use regexp

, if you like - and tedious, but not rocket science.



0


source


In C ++ 11, you can use highly synchronized objects in <chrono>

, see the answers to this question .



0


source







All Articles