咋一看也没什么技术含量,atol就可以搞定的麽~
问题:将时间字符串string timeStr(2010-10-10T11:20:00) -> long nLong(201010101120)
/////////////////////////////////////////////////////////// // Copyright (c) 2013, ShangHai xxxxx Inc. // // FileName: a.cpp // // Description: // // Created: Wed Oct 9 15:58:41 2013 // Revision: Revision: 1.0 // Compiler: g++ // /////////////////////////////////////////////////////////// #include <stdio.h> #include <stdlib.h> #include <string> using namespace std; int main() { string timeStr("2013-10-09T15:58:41"); string::iterator it = timeStr.begin(); for(; it != timeStr.end(); it++) { if(*it == '-' || *it == 'T' || *it == ':') timeStr.erase(it); } long nLong = atol(timeStr.c_str()); printf("%ld ",nLong); return 0; }
简单吧~来看下结果:
[yangtze@contex201 ~]$ g++ -o a a.cpp [yangtze@contex201 ~]$ ./a 20131009155841