Converts a time string to a time string in milliseconds.

Source: Internet
Author: User

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}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.