I'm trying to extract the time section from an ISO8601 timestamp.
e.g. From the following timstamp"0001-01-01T17:45:33" I want to extract this part "17:45:33".
I'm trying to extract the time section from an ISO8601 timestamp.
e.g. From the following timstamp"0001-01-01T17:45:33" I want to extract this part "17:45:33".
Copyright © 2021 Jogjafile Inc.
you have a few options.
lets say you have it in a variable char array called
string.now if you know that it the time will always be at the end of the string it`s very easy you can just do:
if it's more complex you have to do some more analyzing to find it. either manually or use different available tools like
sscanf()or something else. make sure to specifiec widths forsscanfs().http://www.tutorialspoint.com/c_standard_library/c_function_sscanf.htm
if the
Tindicates the start of the time you can look for it with strchr:It really depends on how variable the input is... If it is just a singular example you can use either. Allthough the last one is more efficient.
You indicated that it is an ISO 8601 timestamp. then I would just use the 2nd method.