在cpp中对字符串进行转换 [英] coversion of string to date in cpp
本文介绍了在cpp中对字符串进行转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我想将字符串2013年1月4日转换为2013-01- 04。
我怎么能这样做。有任何简单的方法可以做到这一点。
请分享一些代码。
我该怎么做。
问候,
Shefeek
Hi all,
I would like to convert the string "January 4, 2013" in to "2013-01-04".
How can i do this.Is there any easy way to do this.
Please share some code.
how can i do this.
Regards,
Shefeek
推荐答案
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;
我认为它的使用方法
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;
i think its use ful
这篇关于在cpp中对字符串进行转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文