simple way to convert string to date in C++
Nov 26, 2010 at 4:13am UTC
I realize this function strptime is not availabe in windows VC. but I don't want to use MFC, just want a simple and light way to convert a YYYYMMDD HHMISS to a tm.
any advice ?
Nov 27, 2010 at 1:23am UTC
hi
I wrote this short program so that you can see how to do it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <iostream>
#include <stdio.h>
using namespace std;
int main(int argc,char * argv)
{
char * str = "20101127 090600" ;
tm tm1;
sscanf(str,"%4d%2d%2d %2d%2d%2d" ,&tm1.tm_year,&tm1.tm_mon,&tm1.tm_mday,
&tm1.tm_hour,&tm1.tm_min,&tm1.tm_sec);
cout << tm1.tm_year << endl << tm1.tm_mon << endl << tm1.tm_mday << endl;
cout << tm1.tm_hour << endl << tm1.tm_min << endl << tm1.tm_sec << endl;
}
hope thats what you were after
Shredded
Dec 1, 2010 at 6:57am UTC
thanks... very smart.
Topic archived. No new replies allowed.