-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStrptime.cpp
More file actions
42 lines (33 loc) · 930 Bytes
/
Strptime.cpp
File metadata and controls
42 lines (33 loc) · 930 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* \file Strptime.cpp
* \brief Convert (parse) a string representation of time to a time tm structure
*/
#include <StdStream/StdStream.h>
#include <StdTest/StdTest.h>
//-------------------------------------------------------------------------------------------------
int main(int, char **)
{
const std::string dateFormats[]
{
"%I:%M %p",
"%I:%M",
"%H:%M",
"%H:%M:%S"
};
for (const auto &it_dateFormat : dateFormats) {
struct tm dt {};
char *pszRv = strptime("3:15 PM", it_dateFormat.c_str(), &dt);
// STD_TEST(pszRv == nullptr);
std::cout
<< "rv: " << (pszRv == nullptr) << ", "
<< it_dateFormat << " -> " << dt.tm_hour << ":" << dt.tm_min << std::endl;
}
return 0;
}
//-------------------------------------------------------------------------------------------------
#if OUTPUT
rv: 0, %I:%M %p -> 15:15
rv: 0, %I:%M -> 3:15
rv: 0, %H:%M -> 3:15
rv: 1, %H:%M:%S -> 3:15
#endif