|
|
闲来无事,乱写一通
- #include <ctime>
- #include <string>
- #include <iostream>
- using namespace std;
- int main()
- {
- time_t tTime;
- time(&tTime);
- tm* tLocalTime;
- tLocalTime = localtime(&tTime);
- const string sSampleTime = "2008-04-01 08:51:10";
- string sTimeFormat = "%Y-%m-%d %H:%M:%S";
- char* spTime = new char[sSampleTime.size()+1]; //+1 是因为char* 需要一个'\0'作为结束符
- strftime(spTime, sSampleTime.size()+1, sTimeFormat.c_str(), tLocalTime);
- cout << spTime << endl;
- delete[] spTime;
- }
复制代码
回车和空格都给过滤掉了?faint |
|