Converts a time string to a time string in milliseconds.
Two days ago, I met a time to convert the string format to the time expressed in milliseconds. As a beginner, I suddenly had no clue, so I could only search for various types. Finally, the desired results are achieved. Run the code first. If something is wrong, I hope you can correct it.
1 # include <iostream> 2 # include <afx. h> // in non-MFC, the header file CString must contain 3 using namespace std; 4 5 INT64 ChangeTimeStringToMillisconds (CString strTime); 6 7 void main () 8 {9 CString str = "21:39:01. 234 "; 10 INT64 miao = ChangeTimeStringToMillisconds (str); 11 // cout <miao <endl; // <the operator is not overloaded by INT64 error C2593: 'operator <'is ambiguous12 printf ("% I64d \ n", miao); 13} 14 15 INT64 ChangeTimeStringToMillisconds (CString strTime) 16 {17 char buf [100]; 18 tm t; 19 int nms = 0; 20 memset (& t, 0, sizeof (tm); 21 sscanf (strTime, _ T ("% [^ \ t]"), buf, 100); 22 sscanf (buf, _ T ("% d-% d: % d: % d. % d "), & t. tm_year, & t. tm_mon, & t. tm_mday, & t. tm_hour, & t. tm_min, & t. tm_sec, & nms); 23 if (t. tm_year> = 1900) 24 & (t. tm_mon> = 1 & t. tm_mon <= 12) 25 & (t. tm_mday> = 1 & t. tm_mday <= 31) 26 & (t. tm_hour> = 0 & t. tm_hour <= 59) 27 & (t. tm_min> = 0 & t. tm_min <= 59) 28 & (t. tm_sec> = 0 & t. tm_sec <= 59) 29 {30 CTime time (t. tm_year, t. tm_mon, t. tm_mday, t. tm_hour, t. tm_min, t. tm_sec); 31 INT64 nmstime = time. getTime () * 1000 + nms; // time. getTime () returns 32 return nmstime; 33} 34 return 0; 35}